Skip to content

Commit

Permalink
exec: Always NULL-terminate the read buffer
Browse files Browse the repository at this point in the history
CID #200052

(cherry picked from commit 0230f9c)
  • Loading branch information
liviuchircu committed Jul 17, 2020
1 parent 72f8888 commit 1cdea21
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions modules/exec/exec.c
Expand Up @@ -262,8 +262,8 @@ int resume_async_exec(int fd, struct sip_msg *msg, void *param)

do {
n=read( fd, buf+len, MAX_LINE_SIZE-len);
LM_DBG(" read %d [%.*s] \n",n, n<0?0:n,buf+len);
if (n<0) {
LM_DBG("read error: %d\n", n);
if (errno==EINTR) continue;
if (errno==EAGAIN || errno==EWOULDBLOCK) {
/* nothing more to read */
Expand All @@ -285,6 +285,10 @@ int resume_async_exec(int fd, struct sip_msg *msg, void *param)
/* terminate everything */
goto error;
}

buf[len+n] = '\0';
LM_DBG("read %d [%.*s]\n", n, n, buf+len);

/* EOF ? */
if (n==0) {
if (len) {
Expand All @@ -300,7 +304,7 @@ int resume_async_exec(int fd, struct sip_msg *msg, void *param)
break;
}
/* successful reading ( n>0 ) */
LM_DBG(" having %d [%.*s] \n", len+n, len+n, buf);
LM_DBG("buf is now %d [%.*s] \n", len+n, len+n, buf);
if (n+len==MAX_LINE_SIZE) {
/* we have full buffer, pack it as a line */
buf[n+len] = '\n';
Expand Down

0 comments on commit 1cdea21

Please sign in to comment.