summaryrefslogtreecommitdiff
path: root/packages/gsm/files/fix-mlbuf.patch
blob: ed4aa2519d461efebfa2a2ad50f191668dcd3553 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
Index: gsm/src/gsmd/atcmd.c
===================================================================
--- gsm/src/gsmd/atcmd.c	(revision 2745)
+++ gsm/src/gsmd/atcmd.c	(working copy)
@@ -370,8 +370,8 @@
 	if (g->mlbuf_len)
 		g->mlbuf[g->mlbuf_len ++] = '\n';
 	DEBUGP("Appending buf to mlbuf\n");
-	if (len > sizeof(g->mlbuf) - g->mlbuf_len)
-		len = sizeof(g->mlbuf) - g->mlbuf_len;
+	if (len > MLPARSE_BUF_SIZE - g->mlbuf_len)
+		len = MLPARSE_BUF_SIZE - g->mlbuf_len;
 	memcpy(g->mlbuf + g->mlbuf_len, buf, len);
 	g->mlbuf_len += len;
 
@@ -470,7 +470,7 @@
 			if (cr)
 				len = cr - pos->cur;
 			else
-				len = pos->buflen;
+				len = pos->buflen - 1;  /* assuming zero-terminated strings */
 			rc = write(fd, pos->cur, len);
 			if (rc == 0) {
 				gsmd_log(GSMD_ERROR, "write returns 0, aborting\n");
@@ -480,8 +480,8 @@
 					fd, rc);
 				return rc;
 			}
-			if (cr && rc == len)
-				rc ++;	/* Skip the \n */
+			if (!cr || rc == len)
+				rc ++;	/* Skip the \n or \0 */
 			pos->buflen -= rc;
 			pos->cur += rc;
 			write(fd, "\r", 1);
Index: gsm/src/gsmd/gsmd.c
===================================================================
--- gsm/src/gsmd/gsmd.c	(revision 2745)
+++ gsm/src/gsmd/gsmd.c	(working copy)
@@ -301,6 +301,10 @@
 {
 	INIT_LLIST_HEAD(&g->users);
 
+	g->mlbuf = talloc_array(gsmd_tallocs, unsigned char, MLPARSE_BUF_SIZE);
+	if (!g->mlbuf)
+		return -ENOMEM;
+
 	return 0;
 }