From: Denis Vlasenko Date: Sat, 31 Mar 2007 10:17:24 +0000 (-0000) Subject: unzip: fix xstrndup bug (xstrndup(s,n) can allocate less than n bytes!) X-Git-Tag: 1_6_0~274 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=666c40c9fce062f7466f424176ef2d0b8f581b38;p=oweals%2Fbusybox.git unzip: fix xstrndup bug (xstrndup(s,n) can allocate less than n bytes!) --- diff --git a/archival/unzip.c b/archival/unzip.c index 5e631705c..8a9034fc3 100644 --- a/archival/unzip.c +++ b/archival/unzip.c @@ -134,7 +134,8 @@ int unzip_main(int argc, char **argv) break; case 1 : /* The zip file */ - src_fn = xstrndup(optarg, strlen(optarg)+4); + src_fn = xmalloc(strlen(optarg)+4); + strcpy(src_fn, optarg); opt_range++; break; @@ -195,7 +196,7 @@ int unzip_main(int argc, char **argv) src_fd = open(src_fn, O_RDONLY); } if (src_fd == -1) { - src_fn[orig_src_fn_len] = 0; + src_fn[orig_src_fn_len] = '\0'; bb_error_msg_and_die("cannot open %s, %s.zip, %s.ZIP", src_fn, src_fn, src_fn); } }