Browse Source

Plan 9 from Bell Labs 2008-09-03

David du Colombier 13 years ago
parent
commit
518c8b8aae

+ 14 - 13
dist/replica/_plan9.db

@@ -8985,28 +8985,28 @@ sys/src/ape/lib/ap/syscall/mkfile - 664 sys sys 1175915050 499
 sys/src/ape/lib/bsd - 20000000775 sys sys 1212357942 0
 sys/src/ape/lib/bsd/_sock_ingetaddr.c - 664 sys sys 1014921994 836
 sys/src/ape/lib/bsd/_sock_ipattr.c - 664 sys sys 1014921994 577
-sys/src/ape/lib/bsd/_sock_srv.c - 664 sys sys 1014921994 883
-sys/src/ape/lib/bsd/accept.c - 664 sys sys 1018029972 2012
+sys/src/ape/lib/bsd/_sock_srv.c - 664 sys sys 1220397750 976
+sys/src/ape/lib/bsd/accept.c - 664 sys sys 1220397766 2016
 sys/src/ape/lib/bsd/bcopy.c - 664 sys sys 1014921994 246
-sys/src/ape/lib/bsd/bind.c - 664 sys sys 1014921994 1204
-sys/src/ape/lib/bsd/connect.c - 664 sys sys 1014921994 2150
+sys/src/ape/lib/bsd/bind.c - 664 sys sys 1220397762 1216
+sys/src/ape/lib/bsd/connect.c - 664 sys sys 1220397758 2191
 sys/src/ape/lib/bsd/endhostent.c - 664 sys sys 1014921994 26
 sys/src/ape/lib/bsd/ffs.c - 664 sys sys 1014921995 249
 sys/src/ape/lib/bsd/getdtablesize.c - 664 sys sys 1014921994 83
 sys/src/ape/lib/bsd/gethostbyaddr.c - 664 sys sys 1014921994 490
-sys/src/ape/lib/bsd/gethostbyname.c - 664 sys sys 1014921995 2163
+sys/src/ape/lib/bsd/gethostbyname.c - 664 sys sys 1220397778 2202
 sys/src/ape/lib/bsd/gethostname.c - 664 sys sys 1014921995 400
 sys/src/ape/lib/bsd/getopt.c - 664 sys sys 1121977156 1054
 sys/src/ape/lib/bsd/getpeername.c - 664 sys sys 1014921995 899
-sys/src/ape/lib/bsd/getprotobyname.c - 664 sys sys 1014921995 1498
-sys/src/ape/lib/bsd/getservbyaddr.c - 664 sys sys 1014921995 308
-sys/src/ape/lib/bsd/getservbyname.c - 664 sys sys 1014921995 1595
+sys/src/ape/lib/bsd/getprotobyname.c - 664 sys sys 1220397728 1511
+sys/src/ape/lib/bsd/getservbyaddr.c - 664 sys sys 1220397718 321
+sys/src/ape/lib/bsd/getservbyname.c - 664 sys sys 1220397712 1621
 sys/src/ape/lib/bsd/getsockname.c - 664 sys sys 1014921995 847
 sys/src/ape/lib/bsd/gettimeofday.c - 664 sys sys 1087406384 759
 sys/src/ape/lib/bsd/inet_addr.c - 664 sys sys 1014921995 770
-sys/src/ape/lib/bsd/inet_ntoa.c - 664 sys sys 1014921995 382
+sys/src/ape/lib/bsd/inet_ntoa.c - 664 sys sys 1220397701 393
 sys/src/ape/lib/bsd/ioctl.c - 664 sys sys 1014921995 561
-sys/src/ape/lib/bsd/listen.c - 664 sys sys 1014921995 2908
+sys/src/ape/lib/bsd/listen.c - 664 sys sys 1220397625 2924
 sys/src/ape/lib/bsd/lstat.c - 664 sys sys 1014921995 282
 sys/src/ape/lib/bsd/mkfile - 664 sys sys 1048644340 810
 sys/src/ape/lib/bsd/mktemp.c - 664 sys sys 1014921995 526
@@ -9014,9 +9014,9 @@ sys/src/ape/lib/bsd/nptohl.c - 664 sys sys 1014921995 140
 sys/src/ape/lib/bsd/ntohl.c - 664 sys sys 1014921995 592
 sys/src/ape/lib/bsd/popen.c - 664 sys sys 1121977157 1615
 sys/src/ape/lib/bsd/priv.h - 664 sys sys 1014921995 1162
-sys/src/ape/lib/bsd/pty.c - 664 sys sys 1014921995 1892
+sys/src/ape/lib/bsd/pty.c - 664 sys sys 1220397620 1918
 sys/src/ape/lib/bsd/putenv.c - 664 sys sys 1014921995 483
-sys/src/ape/lib/bsd/rcmd.c - 664 sys sys 1014921995 2398
+sys/src/ape/lib/bsd/rcmd.c - 664 sys sys 1220397615 2413
 sys/src/ape/lib/bsd/readv.c - 664 sys sys 1014921995 482
 sys/src/ape/lib/bsd/rresvport.c - 664 sys sys 1014921995 638
 sys/src/ape/lib/bsd/send.c - 664 sys sys 1014921995 446
@@ -9024,7 +9024,7 @@ sys/src/ape/lib/bsd/sendto.c - 664 sys sys 1014921995 502
 sys/src/ape/lib/bsd/sethostent.c - 664 sys sys 1212357943 35
 sys/src/ape/lib/bsd/setlinebuf.c - 664 sys sys 1014921995 111
 sys/src/ape/lib/bsd/shutdown.c - 664 sys sys 1014921995 117
-sys/src/ape/lib/bsd/socket.c - 664 sys sys 1014921995 2810
+sys/src/ape/lib/bsd/socket.c - 664 sys sys 1220397610 2838
 sys/src/ape/lib/bsd/socketpair.c - 664 sys sys 1014921995 325
 sys/src/ape/lib/bsd/strcasecmp.c - 664 sys sys 1051635385 343
 sys/src/ape/lib/bsd/strdup.c - 664 sys sys 1014921995 182
@@ -15884,3 +15884,4 @@ usr/glenda/lib/profile - 664 glenda glenda 1105128663 890
 usr/glenda/readme.acme - 664 glenda glenda 1019860628 4753
 usr/glenda/readme.rio - 664 glenda glenda 1019860628 6370
 usr/glenda/tmp - 20000000775 glenda glenda 1020896385 0
+386/lib/ape/libbsd.a - 664 sys sys 1220411684 185404

+ 14 - 14
dist/replica/plan9.db

@@ -556,7 +556,7 @@
 386/lib/ape - 20000000775 sys sys 1197477092 0
 386/lib/ape/lib9.a - 664 sys sys 1205611022 8766
 386/lib/ape/libap.a - 664 sys sys 1219807805 823890
-386/lib/ape/libbsd.a - 664 sys sys 1219693452 183900
+386/lib/ape/libbsd.a - 664 sys sys 1220411684 185404
 386/lib/ape/libdraw.a - 664 sys sys 1219693462 631580
 386/lib/ape/libfmt.a - 664 sys sys 1219693464 156706
 386/lib/ape/libl.a - 664 sys sys 1212377636 9406
@@ -8985,28 +8985,28 @@ sys/src/ape/lib/ap/syscall/mkfile - 664 sys sys 1175915050 499
 sys/src/ape/lib/bsd - 20000000775 sys sys 1212357942 0
 sys/src/ape/lib/bsd/_sock_ingetaddr.c - 664 sys sys 1014921994 836
 sys/src/ape/lib/bsd/_sock_ipattr.c - 664 sys sys 1014921994 577
-sys/src/ape/lib/bsd/_sock_srv.c - 664 sys sys 1014921994 883
-sys/src/ape/lib/bsd/accept.c - 664 sys sys 1018029972 2012
+sys/src/ape/lib/bsd/_sock_srv.c - 664 sys sys 1220397750 976
+sys/src/ape/lib/bsd/accept.c - 664 sys sys 1220397766 2016
 sys/src/ape/lib/bsd/bcopy.c - 664 sys sys 1014921994 246
-sys/src/ape/lib/bsd/bind.c - 664 sys sys 1014921994 1204
-sys/src/ape/lib/bsd/connect.c - 664 sys sys 1014921994 2150
+sys/src/ape/lib/bsd/bind.c - 664 sys sys 1220397762 1216
+sys/src/ape/lib/bsd/connect.c - 664 sys sys 1220397758 2191
 sys/src/ape/lib/bsd/endhostent.c - 664 sys sys 1014921994 26
 sys/src/ape/lib/bsd/ffs.c - 664 sys sys 1014921995 249
 sys/src/ape/lib/bsd/getdtablesize.c - 664 sys sys 1014921994 83
 sys/src/ape/lib/bsd/gethostbyaddr.c - 664 sys sys 1014921994 490
-sys/src/ape/lib/bsd/gethostbyname.c - 664 sys sys 1014921995 2163
+sys/src/ape/lib/bsd/gethostbyname.c - 664 sys sys 1220397778 2202
 sys/src/ape/lib/bsd/gethostname.c - 664 sys sys 1014921995 400
 sys/src/ape/lib/bsd/getopt.c - 664 sys sys 1121977156 1054
 sys/src/ape/lib/bsd/getpeername.c - 664 sys sys 1014921995 899
-sys/src/ape/lib/bsd/getprotobyname.c - 664 sys sys 1014921995 1498
-sys/src/ape/lib/bsd/getservbyaddr.c - 664 sys sys 1014921995 308
-sys/src/ape/lib/bsd/getservbyname.c - 664 sys sys 1014921995 1595
+sys/src/ape/lib/bsd/getprotobyname.c - 664 sys sys 1220397728 1511
+sys/src/ape/lib/bsd/getservbyaddr.c - 664 sys sys 1220397718 321
+sys/src/ape/lib/bsd/getservbyname.c - 664 sys sys 1220397712 1621
 sys/src/ape/lib/bsd/getsockname.c - 664 sys sys 1014921995 847
 sys/src/ape/lib/bsd/gettimeofday.c - 664 sys sys 1087406384 759
 sys/src/ape/lib/bsd/inet_addr.c - 664 sys sys 1014921995 770
-sys/src/ape/lib/bsd/inet_ntoa.c - 664 sys sys 1014921995 382
+sys/src/ape/lib/bsd/inet_ntoa.c - 664 sys sys 1220397701 393
 sys/src/ape/lib/bsd/ioctl.c - 664 sys sys 1014921995 561
-sys/src/ape/lib/bsd/listen.c - 664 sys sys 1014921995 2908
+sys/src/ape/lib/bsd/listen.c - 664 sys sys 1220397625 2924
 sys/src/ape/lib/bsd/lstat.c - 664 sys sys 1014921995 282
 sys/src/ape/lib/bsd/mkfile - 664 sys sys 1048644340 810
 sys/src/ape/lib/bsd/mktemp.c - 664 sys sys 1014921995 526
@@ -9014,9 +9014,9 @@ sys/src/ape/lib/bsd/nptohl.c - 664 sys sys 1014921995 140
 sys/src/ape/lib/bsd/ntohl.c - 664 sys sys 1014921995 592
 sys/src/ape/lib/bsd/popen.c - 664 sys sys 1121977157 1615
 sys/src/ape/lib/bsd/priv.h - 664 sys sys 1014921995 1162
-sys/src/ape/lib/bsd/pty.c - 664 sys sys 1014921995 1892
+sys/src/ape/lib/bsd/pty.c - 664 sys sys 1220397620 1918
 sys/src/ape/lib/bsd/putenv.c - 664 sys sys 1014921995 483
-sys/src/ape/lib/bsd/rcmd.c - 664 sys sys 1014921995 2398
+sys/src/ape/lib/bsd/rcmd.c - 664 sys sys 1220397615 2413
 sys/src/ape/lib/bsd/readv.c - 664 sys sys 1014921995 482
 sys/src/ape/lib/bsd/rresvport.c - 664 sys sys 1014921995 638
 sys/src/ape/lib/bsd/send.c - 664 sys sys 1014921995 446
@@ -9024,7 +9024,7 @@ sys/src/ape/lib/bsd/sendto.c - 664 sys sys 1014921995 502
 sys/src/ape/lib/bsd/sethostent.c - 664 sys sys 1212357943 35
 sys/src/ape/lib/bsd/setlinebuf.c - 664 sys sys 1014921995 111
 sys/src/ape/lib/bsd/shutdown.c - 664 sys sys 1014921995 117
-sys/src/ape/lib/bsd/socket.c - 664 sys sys 1014921995 2810
+sys/src/ape/lib/bsd/socket.c - 664 sys sys 1220397610 2838
 sys/src/ape/lib/bsd/socketpair.c - 664 sys sys 1014921995 325
 sys/src/ape/lib/bsd/strcasecmp.c - 664 sys sys 1051635385 343
 sys/src/ape/lib/bsd/strdup.c - 664 sys sys 1014921995 182

+ 14 - 0
dist/replica/plan9.log

@@ -36085,3 +36085,17 @@
 1219969804 1 c sys/src/cmd/usb/misc/probe - 775 sys sys 1219968817 253
 1219980604 0 c 386/bin/usb/probe - 775 sys sys 1219979667 253
 1220056205 0 c rc/bin/usbstart - 775 sys sys 1220055238 299
+1220398205 0 c sys/src/ape/lib/bsd/_sock_srv.c - 664 sys sys 1220397750 976
+1220398205 1 c sys/src/ape/lib/bsd/accept.c - 664 sys sys 1220397766 2016
+1220398205 2 c sys/src/ape/lib/bsd/bind.c - 664 sys sys 1220397762 1216
+1220398205 3 c sys/src/ape/lib/bsd/connect.c - 664 sys sys 1220397758 2191
+1220398205 4 c sys/src/ape/lib/bsd/gethostbyname.c - 664 sys sys 1220397778 2202
+1220398205 5 c sys/src/ape/lib/bsd/getprotobyname.c - 664 sys sys 1220397728 1511
+1220398205 6 c sys/src/ape/lib/bsd/getservbyaddr.c - 664 sys sys 1220397718 321
+1220398205 7 c sys/src/ape/lib/bsd/getservbyname.c - 664 sys sys 1220397712 1621
+1220398205 8 c sys/src/ape/lib/bsd/inet_ntoa.c - 664 sys sys 1220397701 393
+1220398205 9 c sys/src/ape/lib/bsd/listen.c - 664 sys sys 1220397625 2924
+1220398205 10 c sys/src/ape/lib/bsd/pty.c - 664 sys sys 1220397620 1918
+1220398205 11 c sys/src/ape/lib/bsd/rcmd.c - 664 sys sys 1220397615 2413
+1220398205 12 c sys/src/ape/lib/bsd/socket.c - 664 sys sys 1220397610 2838
+1220412605 0 c 386/lib/ape/libbsd.a - 664 sys sys 1220411684 185404

+ 3 - 2
sys/src/ape/lib/bsd/_sock_srv.c

@@ -13,6 +13,7 @@
 
 #include "priv.h"
 
+/* we can't avoid overrunning npath because we don't know how big it is. */
 void
 _sock_srvname(char *npath, char *path)
 {
@@ -31,7 +32,7 @@ int
 _sock_srv(char *path, int fd)
 {
 	int sfd;
-	char msg[128];
+	char msg[8+256+1];
 
 	/* change the path to something in srv */
 	_sock_srvname(msg, path);
@@ -46,7 +47,7 @@ _sock_srv(char *path, int fd)
 		_syserrno();
 		return -1;
 	}
-	sprintf(msg, "%d", fd);
+	snprintf(msg, sizeof msg, "%d", fd);
 	if(write(sfd, msg, strlen(msg)) < 0){
 		_syserrno();
 		close(sfd);

+ 1 - 1
sys/src/ape/lib/bsd/accept.c

@@ -22,7 +22,7 @@ accept(int fd, void *a, int *alen)
 	Rock *r, *nr;
 	struct sockaddr_in *ip;
 	char name[Ctlsize];
-	char file[Ctlsize];
+	char file[8+Ctlsize+1];
 	char *p, *net;
 
 	r = _sock_findrock(fd, 0);

+ 2 - 2
sys/src/ape/lib/bsd/bind.c

@@ -52,9 +52,9 @@ bind(int fd, void *a, int alen)
 	}
 	lip = (struct sockaddr_in*)&r->addr;
 	if(lip->sin_port > 0)
-		sprintf(msg, "bind %d", ntohs(lip->sin_port));
+		snprintf(msg, sizeof msg, "bind %d", ntohs(lip->sin_port));
 	else
-		sprintf(msg, "bind *");
+		strcpy(msg, "bind *");
 	n = write(cfd, msg, strlen(msg));
 	if(n < 0){
 		errno = EOPNOTSUPP;	/* Improve error reporting!!! */

+ 5 - 6
sys/src/ape/lib/bsd/connect.c

@@ -20,8 +20,7 @@ connect(int fd, void *a, int alen)
 {
 	Rock *r;
 	int n, cfd, nfd;
-	char msg[128];
-	char file[128];
+	char msg[8+256+1], file[8+256+1];
 	struct sockaddr_in *lip, *rip;
 	struct sockaddr_un *runix;
 	static int vers;
@@ -48,13 +47,13 @@ connect(int fd, void *a, int alen)
 		rip = a;
 		lip = (struct sockaddr_in*)&r->addr;
 		if(lip->sin_port)
-			sprintf(msg, "connect %s!%d%s %d",
+			snprintf(msg, sizeof msg, "connect %s!%d%s %d",
 				inet_ntoa(rip->sin_addr), ntohs(rip->sin_port),
 				r->reserved ? "!r" : "",
 				ntohs(lip->sin_port));
 		else
-			sprintf(msg, "connect %s!%d%s", inet_ntoa(rip->sin_addr),
-				ntohs(rip->sin_port),
+			snprintf(msg, sizeof msg, "connect %s!%d%s",
+				inet_ntoa(rip->sin_addr), ntohs(rip->sin_port),
 				r->reserved ? "!r" : "");
 		n = write(cfd, msg, strlen(msg));
 		if(n < 0){
@@ -76,7 +75,7 @@ connect(int fd, void *a, int alen)
 		}
 
 		/* put far end of our pipe in /srv */
-		sprintf(msg, "UD.%d.%d", getpid(), vers++);
+		snprintf(msg, sizeof msg, "UD.%d.%d", getpid(), vers++);
 		if(_sock_srv(msg, r->other) < 0){
 			r->other = -1;
 			return -1;

+ 3 - 3
sys/src/ape/lib/bsd/gethostbyname.c

@@ -52,13 +52,13 @@ gethostbyname(char *name)
 	/* construct the query, always expect an ip# back */
 	switch(t){
 	case Tsys:
-		sprintf(buf, "!sys=%s ip=*", name);
+		snprintf(buf, sizeof buf, "!sys=%s ip=*", name);
 		break;
 	case Tdom:
-		sprintf(buf, "!dom=%s ip=*", name);
+		snprintf(buf, sizeof buf, "!dom=%s ip=*", name);
 		break;
 	case Tip:
-		sprintf(buf, "!ip=%s", name);
+		snprintf(buf, sizeof buf, "!ip=%s", name);
 		break;
 	}
 

+ 1 - 1
sys/src/ape/lib/bsd/getprotobyname.c

@@ -41,7 +41,7 @@ struct protoent *getprotobyname(const char *name) {
 	}
 
 	/* construct the query, always expect a protocol# back */
-	sprintf(buf, "!protocol=%s ipv4proto=*", name);
+	snprintf(buf, sizeof buf, "!protocol=%s ipv4proto=*", name);
 
 	/* query the server */
 	if(write(fd, buf, strlen(buf)) < 0){

+ 1 - 1
sys/src/ape/lib/bsd/getservbyaddr.c

@@ -13,6 +13,6 @@ getservbyport(int port, char *proto)
 {
 	char buf[32];
 
-	sprintf(buf, "%d", port);
+	snprintf(buf, sizeof buf, "%d", port);
 	return getservbyname(buf, proto);
 }

+ 2 - 2
sys/src/ape/lib/bsd/getservbyname.c

@@ -50,9 +50,9 @@ getservbyname(char *name, char *proto)
 
 	/* construct the query, always expect an ip# back */
 	if(num)
-		sprintf(buf, "!port=%s %s=*", name, proto);
+		snprintf(buf, sizeof buf, "!port=%s %s=*", name, proto);
 	else
-		sprintf(buf, "!%s=%s port=*", proto, name);
+		snprintf(buf, sizeof buf, "!%s=%s port=*", proto, name);
 
 	/* query the server */
 	if(write(fd, buf, strlen(buf)) < 0){

+ 1 - 1
sys/src/ape/lib/bsd/inet_ntoa.c

@@ -17,6 +17,6 @@ inet_ntoa(struct in_addr in)
 	unsigned char *p;	
 
 	p = (unsigned char*)&in.s_addr;
-	sprintf(s, "%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
+	snprintf(s, sizeof s, "%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
 	return s;
 }

+ 3 - 2
sys/src/ape/lib/bsd/listen.c

@@ -142,10 +142,11 @@ listen(fd, backlog)
 				close(cfd);
 				return -1;
 			}
-			sprintf(msg, "announce %d", ntohs(lip->sin_port));
+			snprintf(msg, sizeof msg, "announce %d",
+				ntohs(lip->sin_port));
 		}
 		else
-			sprintf(msg, "announce *");
+			strcpy(msg, "announce *");
 		n = write(cfd, msg, strlen(msg));
 		if(n < 0){
 			errno = EOPNOTSUPP;	/* Improve error reporting!!! */

+ 2 - 2
sys/src/ape/lib/bsd/pty.c

@@ -27,7 +27,7 @@ ptsname(int fd)
 		_syserrno();
 		return 0;
 	}
-	sprintf(buf, "/dev/ptty%d", atoi(d->name+4));
+	snprintf(buf, sizeof buf, "/dev/ptty%d", atoi(d->name+4));
 	free(d);
 	return buf;
 }
@@ -47,7 +47,7 @@ ptmname(int fd)
 		return 0;
 	}
 
-	sprintf(buf, "/dev/ttym%d", atoi(d->name+4));
+	snprintf(buf, sizeof buf, "/dev/ttym%d", atoi(d->name+4));
 	return buf;
 }
 

+ 3 - 3
sys/src/ape/lib/bsd/rcmd.c

@@ -15,8 +15,8 @@
 
 #include "priv.h"
 
-static char *pbotch = "rcmd: protocol botch\n";
-static char *lbotch = "rcmd: botch starting error stream\n";
+static char pbotch[] = "rcmd: protocol botch\n";
+static char lbotch[] = "rcmd: botch starting error stream\n";
 
 static void
 ding(int x)
@@ -73,7 +73,7 @@ rcmd(char **dst, int port, char *luser, char *ruser, char *cmd, int *fd2p)
 			return -1;
 		}
 
-		sprintf(buf, "%d", port2);
+		snprintf(buf, sizeof buf, "%d", port2);
 		if(write(fd, buf, strlen(buf)+1) < 0){
 			close(fd);
 			close(lfd);

+ 2 - 2
sys/src/ape/lib/bsd/socket.c

@@ -75,7 +75,7 @@ _sock_data(int cfd, char *net, int domain, int stype, int protocol, Rock **rp)
 	}
 	name[n] = 0;
 	n = strtoul(name, 0, 0);
-	sprintf(name, "/net/%s/%d/data", net, n);
+	snprintf(name, sizeof name, "/net/%s/%d/data", net, n);
 
 	/* open data file */
 	fd = open(name, O_RDWR);
@@ -87,7 +87,7 @@ _sock_data(int cfd, char *net, int domain, int stype, int protocol, Rock **rp)
 	}
 
 	/* hide stuff under the rock */
-	sprintf(name, "/net/%s/%d/ctl", net, n);
+	snprintf(name, sizeof name, "/net/%s/%d/ctl", net, n);
 	r = _sock_newrock(fd);
 	if(r == 0){
 		errno = ENOBUFS;