# HG changeset patch # User Ashwini Sharma # Date 1407845341 18000 # Node ID 00c20f410c46fdbd4caa3fcc9b357e937c7a4591 # Parent cd5c621193910fc97dffbc2884a8dcb1fcf3f2fa Patches to commands for issues reported from static analysis tool. portability.h.patch - it is for O_CLOEXEC, as compiler complained of it. Makefile.patch - for cleaning generated/*.o files and libopts.dat file [Fixup to uniq.c from Rob.] diff -r cd5c62119391 -r 00c20f410c46 lib/portability.h --- a/lib/portability.h Mon Aug 11 20:15:19 2014 -0500 +++ b/lib/portability.h Tue Aug 12 07:09:01 2014 -0500 @@ -170,6 +170,10 @@ #define O_NOFOLLOW 0 #endif +#ifndef O_CLOEXEC +#define O_CLOEXEC 02000000 +#endif + #if defined(__SIZEOF_DOUBLE__) && defined(__SIZEOF_LONG__) \ && __SIZEOF_DOUBLE__ <= __SIZEOF_LONG__ typedef double FLOAT; diff -r cd5c62119391 -r 00c20f410c46 toys/other/ifconfig.c --- a/toys/other/ifconfig.c Mon Aug 11 20:15:19 2014 -0500 +++ b/toys/other/ifconfig.c Tue Aug 12 07:09:01 2014 -0500 @@ -421,7 +421,7 @@ } if ((p-ptr) != count || *hw_addr) - error_exit("bad hw-addr '%s'", hw_addr ? hw_addr : ""); + error_exit("bad hw-addr '%s'", *argv); // the linux kernel's "struct sockaddr" (include/linux/socket.h in the // kernel source) only has 14 bytes of sa_data, and an infiniband address diff -r cd5c62119391 -r 00c20f410c46 toys/pending/arp.c --- a/toys/pending/arp.c Mon Aug 11 20:15:19 2014 -0500 +++ b/toys/pending/arp.c Tue Aug 12 07:09:01 2014 -0500 @@ -175,7 +175,7 @@ flags = ATF_PERM | ATF_COM; if (toys.optargs[2]) check_flags(&flags, (toys.optargs+2)); req.arp_flags = flags; - strncpy(req.arp_dev, TT.device, sizeof(TT.device)); + strncpy(req.arp_dev, TT.device, sizeof(req.arp_dev)); xioctl(TT.sockfd, SIOCSARP, &req); if (toys.optflags & FLAG_v) xprintf("Entry set for %s\n", toys.optargs[0]); @@ -204,7 +204,7 @@ flags = ATF_PERM; if (toys.optargs[1]) check_flags(&flags, (toys.optargs+1)); req.arp_flags = flags; - strncpy(req.arp_dev, TT.device, sizeof(TT.device)); + strncpy(req.arp_dev, TT.device, sizeof(req.arp_dev)); xioctl(TT.sockfd, SIOCDARP, &req); if (toys.optflags & FLAG_v) xprintf("Delete entry for %s\n", toys.optargs[0]); @@ -301,6 +301,7 @@ if (CFG_TOYBOX_FREE) { free(host_ip); + free(buf); xclose(fd); } } diff -r cd5c62119391 -r 00c20f410c46 toys/pending/fsck.c --- a/toys/pending/fsck.c Mon Aug 11 20:15:19 2014 -0500 +++ b/toys/pending/fsck.c Tue Aug 12 07:09:01 2014 -0500 @@ -216,10 +216,13 @@ } if (toys.optflags & FLAG_N) { + for (j=0;j (N1,N2,N3,N4,P1,P2) garbage. //Server's IP is N1.N2.N3.N4 //Server's port for data connection is P1*256+P2. - if ((pch = strrchr(toybuf, ')'))) *pch = '\0'; - if ((pch = strrchr(toybuf, ','))) *pch = '\0'; + if (!(pch = strrchr(toybuf, ')'))) goto close_stream; + *pch = '\0'; + if (!(pch = strrchr(toybuf, ','))) goto close_stream; + *pch = '\0'; + portnum = atolx_range(pch + 1, 0, 255); - if ((pch = strrchr(toybuf, ','))) *pch = '\0'; + if (!(pch = strrchr(toybuf, ','))) goto close_stream; + *pch = '\0'; portnum = portnum + (atolx_range(pch + 1, 0, 255) * 256); setport(htons(portnum)); if (TT.isget && get_ftp_response("SIZE", r_filename) != FTPFILE_STATUS) TT.c = 0; + return; + +close_stream: + close_stream("PASV"); } /* diff -r cd5c62119391 -r 00c20f410c46 toys/pending/modprobe.c --- a/toys/pending/modprobe.c Mon Aug 11 20:15:19 2014 -0500 +++ b/toys/pending/modprobe.c Tue Aug 12 07:09:01 2014 -0500 @@ -199,7 +199,7 @@ } line[len] = '\0'; *li = xstrdup(line); - if (line) free(line); + free(line); if (nxtline) free(nxtline); return len; } @@ -302,6 +302,7 @@ } free(line); } + fclose(fe); return ret; } diff -r cd5c62119391 -r 00c20f410c46 toys/pending/tar.c --- a/toys/pending/tar.c Mon Aug 11 20:15:19 2014 -0500 +++ b/toys/pending/tar.c Tue Aug 12 07:09:01 2014 -0500 @@ -84,8 +84,8 @@ cnt = size/512 + (rem?1:0); for (i = 0; i < cnt; i++) { - rd = (((i == cnt-1) && rem)? rem:512); - if (readall(src, toybuf, rd) != rd) error_exit("short read"); + rd = (i == cnt-1 && rem) ? rem : 512; + xreadall(src, toybuf, rd); writeall(dst, toybuf, rd); } } @@ -93,11 +93,10 @@ //convert to octal static void itoo(char *str, int len, off_t val) { - char *t, tmp[sizeof(off_t)*3+1]; //1 for NUL termination + char *t, tmp[sizeof(off_t)*3+1]; int cnt = sprintf(tmp, "%0*llo", len, val); - t = tmp; - t += (cnt - len); + t = tmp + cnt - len; if (*t == '0') t++; memcpy(str, t, len); } @@ -547,7 +546,9 @@ break; } } - return ((value)?xstrdup(value) : NULL); + if (value) value = xstrdup(value); + free(buf); + return value; } static void tar_skip(struct archive_handler *tar, int sz) diff -r cd5c62119391 -r 00c20f410c46 toys/posix/uniq.c --- a/toys/posix/uniq.c Mon Aug 11 20:15:19 2014 -0500 +++ b/toys/posix/uniq.c Tue Aug 12 07:09:01 2014 -0500 @@ -113,6 +113,8 @@ print_line(outfile, prevline); if (CFG_TOYBOX_FREE) { + if (outfile != stdout) fclose(outfile); + if (infile != stdin) fclose(infile); free(prevline); free(thisline); }