Avoid writing beyond the end of the buffer we were given.

This should actually cure the "stack overflow" reported earlier (and
was worked around by increasing the size of the buffer).
This commit is contained in:
pgoyette 2016-10-26 06:10:39 +00:00
parent 56b9040c4f
commit 1656c8e745
1 changed files with 7 additions and 3 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: dev_verbose.c,v 1.2 2016/02/03 05:29:43 christos Exp $ */
/* $NetBSD: dev_verbose.c,v 1.3 2016/10/26 06:10:39 pgoyette Exp $ */
/*
* Redistribution and use in source and binary forms, with or without
@ -23,7 +23,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: dev_verbose.c,v 1.2 2016/02/03 05:29:43 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: dev_verbose.c,v 1.3 2016/10/26 06:10:39 pgoyette Exp $");
#include <sys/param.h>
@ -41,10 +41,14 @@ dev_untokenstring(const char *words, const uint16_t *token, char *buf,
size_t len)
{
char *cp = buf;
size_t newlen;
buf[0] = '\0';
for (; *token != 0; token++) {
cp = buf + strlcat(buf, words + *token, len - 2);
newlen = strlcat(buf, words + *token, len - 2);
if (newlen > len - 2)
newlen = len - 2;
cp = buf + newlen;
cp[0] = ' ';
cp[1] = '\0';
}