From 513fbd0234464c2e24a0d2e7cdf2faae5c7ab477 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Sun, 20 May 2007 19:50:04 +0000 Subject: [PATCH] Fix issue with [1843]; we can't use strlen() here as we can be given an unterminated input string. svn path=/trunk/yasm/; revision=1849 --- libyasm/xstrdup.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/libyasm/xstrdup.c b/libyasm/xstrdup.c index 54af2fae..83ac3955 100644 --- a/libyasm/xstrdup.c +++ b/libyasm/xstrdup.c @@ -58,12 +58,11 @@ yasm__xstrdup(const char *str) char * yasm__xstrndup(const char *str, size_t max) { - size_t len; + size_t len = 0; char *copy; - len = strlen(str); - if (len > max) - len = max; + while (len < max && str[len] != '\0') + len++; copy = yasm_xmalloc(len+1); memcpy(copy, str, len); copy[len] = '\0'; -- 2.40.0