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.]
#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;
}
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
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]);
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]);
if (CFG_TOYBOX_FREE) {
free(host_ip);
+ free(buf);
xclose(fd);
}
}
}
if (toys.optflags & FLAG_N) {
+ for (j=0;j<i;j++) free(args[i]);
free(args);
return;
} else {
if ((pid = fork()) < 0) {
+ for (j=0;j<i;j++) free(args[i]);
+ free(args);
perror_msg(args[0]);
return;
}
if (!TT.devices || (toys.optflags & FLAG_A)) {
toys.exitval = scan_all();
if (CFG_TOYBOX_FREE) goto free_all;
+ return; //if CFG_TOYBOX_FREE is not set, exit.
}
dev = TT.devices;
unsigned portnum;
//vsftpd reply like:- "227 Entering Passive Mode (125,19,39,117,43,39)".
- if (get_ftp_response("PASV", NULL) != PASSIVE_MODE) close_stream("PASV");
+ if (get_ftp_response("PASV", NULL) != PASSIVE_MODE) goto close_stream;
//Response is "NNN <some text> (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");
}
/*
}
line[len] = '\0';
*li = xstrdup(line);
- if (line) free(line);
+ free(line);
if (nxtline) free(nxtline);
return len;
}
}
free(line);
}
+ fclose(fe);
return ret;
}
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);
}
}
//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);
}
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)
print_line(outfile, prevline);
if (CFG_TOYBOX_FREE) {
+ if (outfile != stdout) fclose(outfile);
+ if (infile != stdin) fclose(infile);
free(prevline);
free(thisline);
}