[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] Using smsd to send multiline sms
From: |
Jan Derfinak |
Subject: |
Re: [PATCH] Using smsd to send multiline sms |
Date: |
Fri, 18 Jul 2008 11:57:37 +0200 (CEST) |
On Fri, 18 Jul 2008, Joan wrote:
Hi.
> > AFAIR fread() in contrary to fgets() won'd null terminate the read
> > text. So you may end up with some garbage that way. Do you mind fixing
> > this?
> Ok, after working on it for some time and testing in our production
> machine it seems that is working as expected.
> Hope it's fine now.
--- gnokii-0.6.26/smsd/file.c 2007-05-07 20:05:51.000000000 +0200
+++ /root/Sources/gnokii-0.6.26/smsd/file.c 2008-07-18 11:27:18.000000000
+0200
@@ -156,7 +156,7 @@
struct dirent *dirent;
FILE *smsFile;
GString *buf;
- gint numError, error;
+ gint numError, error, mlength;
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.
jan
--
- [PATCH] Using smsd to send multiline sms, Joan, 2008/07/17
- Re: [PATCH] Using smsd to send multiline sms, Pawel Kot, 2008/07/17
- Re: [PATCH] Using smsd to send multiline sms, Joan, 2008/07/18
- Re: [PATCH] Using smsd to send multiline sms, Pawel Kot, 2008/07/18
- Re: [PATCH] Using smsd to send multiline sms,
Jan Derfinak <=
- Re: [PATCH] Using smsd to send multiline sms, Pawel Kot, 2008/07/18
- Re: [PATCH] Using smsd to send multiline sms, Jan Derfinak, 2008/07/18
- Re: [PATCH] Using smsd to send multiline sms, Pawel Kot, 2008/07/18
- Re: [PATCH] Using smsd to send multiline sms, Joan, 2008/07/18
- Re: [PATCH] Using smsd to send multiline sms, Pawel Kot, 2008/07/18
- Re: [PATCH] Using smsd to send multiline sms, Joan, 2008/07/18
- Re: [PATCH] Using smsd to send multiline sms, Jan Derfinak, 2008/07/18
- Re: [PATCH] Using smsd to send multiline sms, Jan Derfinak, 2008/07/18
- Re: [PATCH] Using smsd to send multiline sms, Joan, 2008/07/18
- Re: [PATCH] Using smsd to send multiline sms, Jan Derfinak, 2008/07/18