>From f1c831594e4e44d5c64d43bacd619376de750be1 Mon Sep 17 00:00:00 2001 From: KO Myung-Hun
Date: Sat, 22 Nov 2014 12:34:14 +0900 Subject: [PATCH] libm4: fix regression of 2c19e82d5d813565abfc2aca0085e1da339416fd path_truncate() expects a null-terminated string. So ensure that a null-terminator is appended. path_truncate() may change path. So re-calculate a length of path after path_truncate(). * m4/path.c (m4_path_search): Ensure that a null-terminator is appended. Re-calculate a length of path after path_truncate(). --- m4/path.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/m4/path.c b/m4/path.c index 44ed620..7243447 100644 --- a/m4/path.c +++ b/m4/path.c @@ -227,7 +227,8 @@ m4_path_search (m4 *context, const char *filename, const char **suffixes) size_t mem = strlen (filename); /* Try appending each of the suffixes we were given. */ - filepath = path_truncate (strncpy (xmalloc (mem + max_suffix_len +1), filename, mem)); + filepath = path_truncate (strncpy (xmalloc (mem + max_suffix_len +1), filename, mem + 1)); + mem = strlen (filepath); for (i = 0; suffixes && suffixes[i]; ++i) { strcpy (filepath + mem, suffixes[i]); @@ -268,7 +269,8 @@ m4_path_search (m4 *context, const char *filename, const char **suffixes) /* Capture errno only when searching `.'. */ e = errno; - filepath = path_truncate (strncpy (xmalloc (mem + max_suffix_len +1), pathname, mem)); + filepath = path_truncate (strncpy (xmalloc (mem + max_suffix_len +1), pathname, mem + 1)); + mem = strlen (filepath); free (pathname); for (i = 0; suffixes && suffixes[i]; ++i) -- 1.8.5.2