librc: fix off-by-one bug

We need allocate space for both the added leading '-' and the trailing
'\0'.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
This commit is contained in:
Natanael Copa 2013-09-26 07:59:29 +00:00 committed by William Hubbs
parent 56d592866c
commit 681a37e7bd

View File

@ -856,7 +856,7 @@ rc_deptree_update(void)
* work for them. This doesn't stop them from being run directly. */ * work for them. This doesn't stop them from being run directly. */
if (sys) { if (sys) {
len = strlen(sys); len = strlen(sys);
nosys = xmalloc(len + 1); nosys = xmalloc(len + 2);
nosys[0] = '-'; nosys[0] = '-';
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
nosys[i + 1] = (char)tolower((unsigned char)sys[i]); nosys[i + 1] = (char)tolower((unsigned char)sys[i]);