Message ID | 20181219111901.6730-1-hauke@hauke-m.de |
---|---|
State | Superseded |
Delegated to: | Hauke Mehrtens |
Headers | show |
Series | [OpenWrt-Devel,procd] hotplug.c: Make sure hotplug buffer is NULL terminated | expand |
> Op 19 dec. 2018, om 12:19 heeft Hauke Mehrtens <hauke@hauke-m.de> het volgende geschreven: > > Sets the final byte explicitly to NULL because we later do string > operations on this buffer. > > Fixes Coverity issue 1430926 String not null terminated > > Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de> > --- > plug/hotplug.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/plug/hotplug.c b/plug/hotplug.c > index 80e6e4d..37b918e 100644 > --- a/plug/hotplug.c > +++ b/plug/hotplug.c > @@ -545,10 +545,12 @@ static void hotplug_handler(struct uloop_fd *u, unsigned int ev) > { > int i = 0; > static char buf[4096]; > - int len = recv(u->fd, buf, sizeof(buf), MSG_DONTWAIT); > + int len = recv(u->fd, buf, sizeof(buf) - 1, MSG_DONTWAIT); > void *index; > if (len < 1) > return; > + else The else is not needed; after return it's // NEVER REACHED. > + buf[len] = '\0'; > > blob_buf_init(&b, 0); > index = blobmsg_open_table(&b, NULL); > -- > 2.19.2 > > > _______________________________________________ > openwrt-devel mailing list > openwrt-devel@lists.openwrt.org > https://lists.openwrt.org/mailman/listinfo/openwrt-devel
diff --git a/plug/hotplug.c b/plug/hotplug.c index 80e6e4d..37b918e 100644 --- a/plug/hotplug.c +++ b/plug/hotplug.c @@ -545,10 +545,12 @@ static void hotplug_handler(struct uloop_fd *u, unsigned int ev) { int i = 0; static char buf[4096]; - int len = recv(u->fd, buf, sizeof(buf), MSG_DONTWAIT); + int len = recv(u->fd, buf, sizeof(buf) - 1, MSG_DONTWAIT); void *index; if (len < 1) return; + else + buf[len] = '\0'; blob_buf_init(&b, 0); index = blobmsg_open_table(&b, NULL);
Sets the final byte explicitly to NULL because we later do string operations on this buffer. Fixes Coverity issue 1430926 String not null terminated Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de> --- plug/hotplug.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)