From fa0e5d6378ca0619a76d3098ce21bb4c631e43ee Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Tue, 7 Mar 2017 23:10:48 -0800 Subject: [PATCH] libutil/unescape: NULL terminate unescaped string In commit 30fd43d7f3b8716054eb9867c835aadc423f652c, unescape was simplified significantly, but the new version failed to NULL terminate the resulting string. This causes bad behavior in various utilities, for example tr: Broken: $ echo b2 | tr '\142' '\143' c3 Fixed: $ echo b2 | tr '\142' '\143' c2 This bug breaks libtool's usage of tr, causing gcc to fail to build with sbase. --- libutil/unescape.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libutil/unescape.c b/libutil/unescape.c index 7523db3..d8ed2a2 100644 --- a/libutil/unescape.c +++ b/libutil/unescape.c @@ -52,6 +52,7 @@ unescape(char *s) eprintf("invalid escape sequence '\\%c'\n", *r); } } + *w = '\0'; return w - s; }