diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gsmd/atcmd.c | 10 | ||||
-rw-r--r-- | src/gsmd/gsmd.c | 4 |
2 files changed, 9 insertions, 5 deletions
diff --git a/src/gsmd/atcmd.c b/src/gsmd/atcmd.c index 37c8538..2ef6a10 100644 --- a/src/gsmd/atcmd.c +++ b/src/gsmd/atcmd.c @@ -370,8 +370,8 @@ static int ml_parse(const char *buf, int len, void *ctx) 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 @@ static int atcmd_select_cb(int fd, unsigned int what, void *data) 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 @@ static int atcmd_select_cb(int fd, unsigned int what, void *data) 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); diff --git a/src/gsmd/gsmd.c b/src/gsmd/gsmd.c index 2be6d79..51b4f2c 100644 --- a/src/gsmd/gsmd.c +++ b/src/gsmd/gsmd.c @@ -301,6 +301,10 @@ static int gsmd_initialize(struct gsmd *g) { INIT_LLIST_HEAD(&g->users); + g->mlbuf = talloc_array(gsmd_tallocs, unsigned char, MLPARSE_BUF_SIZE); + if (!g->mlbuf) + return -ENOMEM; + return 0; } |