From 7eb3e4364c2bcebd2fdfef52c07f5101aa03e5bb Mon Sep 17 00:00:00 2001 From: Ashwini Sharma Date: Tue, 12 Aug 2014 07:09:01 -0500 Subject: 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.] --- toys/other/ifconfig.c | 2 +- toys/pending/arp.c | 5 +++-- toys/pending/fsck.c | 4 ++++ toys/pending/ftpget.c | 16 ++++++++++++---- toys/pending/modprobe.c | 3 ++- toys/pending/tar.c | 13 +++++++------ toys/posix/uniq.c | 2 ++ 7 files changed, 31 insertions(+), 14 deletions(-) (limited to 'toys') diff --git a/toys/other/ifconfig.c b/toys/other/ifconfig.c index a84e26ac..f5d4215e 100644 --- a/toys/other/ifconfig.c +++ b/toys/other/ifconfig.c @@ -421,7 +421,7 @@ void ifconfig_main(void) } 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 --git a/toys/pending/arp.c b/toys/pending/arp.c index 831facb9..1153ebc1 100644 --- a/toys/pending/arp.c +++ b/toys/pending/arp.c @@ -175,7 +175,7 @@ static int set_entry(void) 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 @@ static int delete_entry(void) 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 @@ void arp_main(void) if (CFG_TOYBOX_FREE) { free(host_ip); + free(buf); xclose(fd); } } diff --git a/toys/pending/fsck.c b/toys/pending/fsck.c index 56dfb5df..ee35c04e 100644 --- a/toys/pending/fsck.c +++ b/toys/pending/fsck.c @@ -216,10 +216,13 @@ static void do_fsck(struct f_sys_info *finfo) } 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 --git a/toys/pending/modprobe.c b/toys/pending/modprobe.c index b8ef4824..cbf929b9 100644 --- a/toys/pending/modprobe.c +++ b/toys/pending/modprobe.c @@ -199,7 +199,7 @@ static int read_line(FILE *fl, char **li) } line[len] = '\0'; *li = xstrdup(line); - if (line) free(line); + free(line); if (nxtline) free(nxtline); return len; } @@ -302,6 +302,7 @@ static int depmode_read_entry(char *cmdname) } free(line); } + fclose(fe); return ret; } diff --git a/toys/pending/tar.c b/toys/pending/tar.c index 12ee7af5..5b060c6e 100644 --- a/toys/pending/tar.c +++ b/toys/pending/tar.c @@ -84,8 +84,8 @@ static void copy_in_out(int src, int dst, off_t size) 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 @@ static void copy_in_out(int src, int dst, off_t size) //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 @@ static char *process_extended_hdr(struct archive_handler *tar, int size) 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 --git a/toys/posix/uniq.c b/toys/posix/uniq.c index bd41d4af..3cfdb947 100644 --- a/toys/posix/uniq.c +++ b/toys/posix/uniq.c @@ -113,6 +113,8 @@ void uniq_main(void) print_line(outfile, prevline); if (CFG_TOYBOX_FREE) { + if (outfile != stdout) fclose(outfile); + if (infile != stdin) fclose(infile); free(prevline); free(thisline); } -- cgit v1.2.3