gnokii-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Using smsd to send multiline sms


From: Pawel Kot
Subject: Re: [PATCH] Using smsd to send multiline sms
Date: Fri, 18 Jul 2008 12:33:21 +0200

Hi,

On Fri, Jul 18, 2008 at 11:57, Jan Derfinak <address@hidden> wrote:
> On Fri, 18 Jul 2008, Joan wrote:
>   if (spool[0] == '\0')  // if user don't set spool dir, sending is disabled
> @@ -193,7 +193,10 @@
>     if (sms.remote.number[strlen (sms.remote.number) - 1] == '\n')
>       sms.remote.number[strlen (sms.remote.number) - 1] = '\0';
>
> -    fgets ((gchar *) sms.user_data[0].u.text, GN_SMS_MAX_LENGTH + 1, 
> smsFile);
> +//    fgets ((gchar *) sms.user_data[0].u.text, GN_SMS_MAX_LENGTH + 1, 
> smsFile);
> +    mlength=fread ((gchar *) sms.user_data[0].u.text, 1, GN_SMS_MAX_LENGTH + 
> 1, smsFile);
> +    if (mlength>0)
> +      sms.user_data[0].u.text[mlength]='\0';
>     if (sms.user_data[0].u.text[strlen ((gchar *) sms.user_data[0].u.text) - 
> 1] == '\n')
>       sms.user_data[0].u.text[strlen ((gchar *) sms.user_data[0].u.text) - 1] 
> = '\0';
>
> Why you terminate sms.user_data[0].u.text only if mlength>0?
> If fread returns 0, no item is readed, sms.user_data[0].u.text is not
> initialized and it is not safe to suppose that it contains NULL terminated
> string (in next line you use strlen on it).
> Just add '\0' on the end of string in any case, even string is empty.

Good point. Additionally there another problem. When there's an empty input
sms.user_data[0].u.text[strlen ((gchar *) sms.user_data[0].u.text) - 1]
will cause segfault. However that problem existed already before the patch.

take care,
pkot
-- 
Pawel Kot




reply via email to

[Prev in Thread] Current Thread [Next in Thread]