Don't look at string[length - 1] if length == 0.

This commit is contained in:
Nicholas Marriott 2013-10-06 21:20:11 +01:00
parent 4538c269d0
commit d86c70af96
2 changed files with 5 additions and 5 deletions

View File

@ -580,7 +580,7 @@ client_dispatch_wait(void *data0)
imsg_free(&imsg); imsg_free(&imsg);
return (-1); return (-1);
case MSG_SHELL: case MSG_SHELL:
if (data[datalen - 1] != '\0') if (datalen == 0 || data[datalen - 1] != '\0')
fatalx("bad MSG_SHELL string"); fatalx("bad MSG_SHELL string");
clear_signals(0); clear_signals(0);
@ -664,7 +664,7 @@ client_dispatch_attached(void)
kill(getpid(), SIGTSTP); kill(getpid(), SIGTSTP);
break; break;
case MSG_LOCK: case MSG_LOCK:
if (data[datalen - 1] != '\0') if (datalen == 0 || data[datalen - 1] != '\0')
fatalx("bad MSG_LOCK string"); fatalx("bad MSG_LOCK string");
system(data); system(data);

View File

@ -961,12 +961,12 @@ server_client_msg_identify(struct client *c, struct imsg *imsg)
c->flags |= flags; c->flags |= flags;
break; break;
case MSG_IDENTIFY_TERM: case MSG_IDENTIFY_TERM:
if (data[datalen - 1] != '\0') if (datalen == 0 || data[datalen - 1] != '\0')
fatalx("bad MSG_IDENTIFY_TERM string"); fatalx("bad MSG_IDENTIFY_TERM string");
c->term = xstrdup(data); c->term = xstrdup(data);
break; break;
case MSG_IDENTIFY_TTYNAME: case MSG_IDENTIFY_TTYNAME:
if (data[datalen - 1] != '\0') if (datalen == 0 || data[datalen - 1] != '\0')
fatalx("bad MSG_IDENTIFY_TTYNAME string"); fatalx("bad MSG_IDENTIFY_TTYNAME string");
c->ttyname = xstrdup(data); c->ttyname = xstrdup(data);
break; break;
@ -981,7 +981,7 @@ server_client_msg_identify(struct client *c, struct imsg *imsg)
c->fd = imsg->fd; c->fd = imsg->fd;
break; break;
case MSG_IDENTIFY_ENVIRON: case MSG_IDENTIFY_ENVIRON:
if (data[datalen - 1] != '\0') if (datalen == 0 || data[datalen - 1] != '\0')
fatalx("bad MSG_IDENTIFY_ENVIRON string"); fatalx("bad MSG_IDENTIFY_ENVIRON string");
if (strchr(data, '=') != NULL) if (strchr(data, '=') != NULL)
environ_put(&c->environ, data); environ_put(&c->environ, data);