[hackers] [sbase] [PATCH] libutil/unescape: NULL terminate unescaped string

From: Michael Forney <mforney_AT_mforney.org>
Date: Tue, 7 Mar 2017 23:10:48 -0800

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
_AT_@ -52,6 +52,7 @@ unescape(char *s)
 			eprintf("invalid escape sequence '\\%c'\n", *r);
 		}
 	}
+	*w = '\0';
 
 	return w - s;
 }
-- 
2.12.0
Received on Wed Mar 08 2017 - 08:10:48 CET

This archive was generated by hypermail 2.3.0 : Wed Mar 08 2017 - 08:12:18 CET