From: Peter Johnson Date: Sun, 20 May 2007 19:50:04 +0000 (-0000) Subject: Fix issue with [1843]; we can't use strlen() here as we can be given X-Git-Tag: v0.6.1~5^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=513fbd0234464c2e24a0d2e7cdf2faae5c7ab477;p=yasm 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 --- 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';