Skip to content

Commit

Permalink
Protect against possibly unterminated strings in IPC.
Browse files Browse the repository at this point in the history
Fix Coverity Scan CID #60565.  The received string in `buf`
may not be NUL terminated.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
  • Loading branch information
troglobit committed Sep 28, 2014
1 parent 38b7bd8 commit 70d0dd9
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions smcroute.c
Expand Up @@ -591,20 +591,21 @@ int main(int argc, const char *argv[])

for (i = 0; !result && i < cmdnum; i++) {
int slen, rlen;
uint8 buf[MX_CMDPKT_SZ];
uint8 buf[MX_CMDPKT_SZ + 1];
struct cmd *command = cmdv[i];

/* Send command */
slen = ipc_send(command, command->len);

/* Wait here for reply */
rlen = ipc_receive(buf, sizeof(buf));
rlen = ipc_receive(buf, MX_CMDPKT_SZ);
if (slen < 0 || rlen < 0) {
smclog(LOG_WARNING, errno, "Communication with daemon failed");
result = 1;
}

if (rlen != 1 || *buf != '\0') {
buf[rlen] = 0;
fprintf(stderr, "Daemon error: %s\n", buf);
result = 1;
}
Expand Down

0 comments on commit 70d0dd9

Please sign in to comment.