ref: e4d29ea9a7ddc5c5b803ff51ba54baff832b9680
parent: b46a3ee95fa92800b2d2890fe57c98cd8d156f2f
parent: 4b7b1218bf85c1d2894a85bc1b15f9b52d618512
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sat Jul 12 21:05:01 EDT 2014
merge
--- a/sys/src/cmd/ip/ftpd.c
+++ b/sys/src/cmd/ip/ftpd.c
@@ -33,7 +33,6 @@
/* maximum ms we'll wait for a command */
Maxwait= 1000*60*30, /* inactive for 30 minutes, we hang up */
- Maxerr= 128,
Maxpath= 512,
};
@@ -161,7 +160,7 @@
{
char buf[8192];
va_list arg;
- char errstr[128];
+ char errstr[ERRMAX];
rerrstr(errstr, sizeof errstr);
va_start(arg, fmt);
@@ -1078,7 +1077,7 @@
dfd = dialdata();
if(dfd < 0){
- reply("425 Error opening data connection:%r");
+ reply("425 Error opening data connection: %r");
return;
}
reply("150 Opened data connection (%s)", data);
@@ -1373,7 +1372,7 @@
reply("150 Opening data connection for %s (%s)", arg, data);
dfd = dialdata();
if(dfd < 0){
- reply("425 Error opening data connection:%r");
+ reply("425 Error opening data connection: %r");
close(fd);
return;
}
@@ -1445,7 +1444,7 @@
reply("150 Opening data connection for %s (%s)", arg, data);
dfd = dialdata();
if(dfd < 0){
- reply("425 Error opening data connection:%r");
+ reply("425 Error opening data connection: %r");
close(fd);
return;
}
@@ -1697,30 +1696,29 @@
{
int fd, cfd;
char ldir[40];
- char err[Maxerr];
+ char err[ERRMAX];
if(mountnet() < 0)
return -1;
- if(!passive.inuse){
+ if(!passive.inuse)
fd = dial(data, "20", 0, 0);
- errstr(err, sizeof err);
- } else {
+ else {
+ fd = -1;
alarm(5*60*1000);
cfd = listen(passive.adir, ldir);
alarm(0);
- errstr(err, sizeof err);
- if(cfd < 0)
- return -1;
- fd = accept(cfd, ldir);
- errstr(err, sizeof err);
- close(cfd);
+ if(cfd >= 0){
+ fd = accept(cfd, ldir);
+ close(cfd);
+ }
}
+ err[0] = 0;
+ errstr(err, sizeof err);
if(fd < 0)
logit("can't dial %s: %s", data, err);
-
unmountnet();
- werrstr(err, sizeof err);
+ errstr(err, sizeof err);
return fd;
}
--- a/sys/src/cmd/ip/tftpd.c
+++ b/sys/src/cmd/ip/tftpd.c
@@ -11,7 +11,6 @@
enum
{
Maxpath= 128,
- Maxerr= 256,
Debug= 0,
@@ -561,7 +560,7 @@
{
int file, block, ret, rexmit, n, txtry;
uchar buf[Maxsegsize+Hdrsize];
- char errbuf[Maxerr];
+ char errbuf[ERRMAX];
file = -1;
syslog(dbg, flog, "tftpd %d send file '%s' %s to %s",
@@ -642,7 +641,7 @@
{
ushort op, block, inblock;
uchar buf[Maxsegsize+8];
- char errbuf[Maxerr];
+ char errbuf[ERRMAX];
int n, ret, file;
syslog(dbg, flog, "receive file '%s' %s from %s", name, mode, raddr);
@@ -651,7 +650,7 @@
if(file < 0) {
errstr(errbuf, sizeof errbuf);
nak(fd, 0, errbuf);
- syslog(dbg, flog, "can't create %s: %r", name);
+ syslog(dbg, flog, "can't create %s: %s", name, errbuf);
return;
}
@@ -729,13 +728,16 @@
char buf[128];
int n;
+ n = 5 + strlen(msg);
+ if(n > sizeof(buf))
+ n = sizeof(buf);
buf[0] = 0;
buf[1] = Tftp_ERROR;
buf[2] = 0;
buf[3] = code;
- strcpy(buf+4, msg);
- n = strlen(msg) + 4 + 1;
- if(write(fd, buf, n) < n)
+ memmove(buf+4, msg, n - 5);
+ buf[n-1] = 0;
+ if(write(fd, buf, n) != n)
sysfatal("write nak: %r");
}