[Debburn-changes] r647 - in cdrkit/trunk: . icedax

Christian Fromme kaner-guest at alioth.debian.org
Thu Dec 28 21:47:47 CET 2006


Author: kaner-guest
Date: 2006-12-28 21:47:46 +0100 (Thu, 28 Dec 2006)
New Revision: 647

Modified:
   cdrkit/trunk/TODO
   cdrkit/trunk/icedax/toc.c
Log:
Inserted checks for return values of readn()


Modified: cdrkit/trunk/TODO
===================================================================
--- cdrkit/trunk/TODO	2006-12-27 22:21:04 UTC (rev 646)
+++ cdrkit/trunk/TODO	2006-12-28 20:47:46 UTC (rev 647)
@@ -15,7 +15,6 @@
    OR
    Stop supporting it, add a warning to libusal (scsi-remote.c or so) to not
    use it, add an appropriate comment to a BUGS file
- - fix nread() callers, see toc.c:835
  - check libparanoia, we may link dynamicaly with it. Quality? Portability?
  - check notes in help output, drop advisories, notes about future plans...
  - find out why spawn.c breaks in WAIT_H while the WAIT_UNION check works quite well on sys/wait.h. See include/CMakeLists.txt comments.

Modified: cdrkit/trunk/icedax/toc.c
===================================================================
--- cdrkit/trunk/icedax/toc.c	2006-12-27 22:21:04 UTC (rev 646)
+++ cdrkit/trunk/icedax/toc.c	2006-12-28 20:47:46 UTC (rev 647)
@@ -823,12 +823,6 @@
 	if (nread < 0) {
 	   perror("socket read error: ");
 	   fprintf(stderr, "fd=%d, ptr=%p, nbytes=%d\n", fd, ptr, nbytes);
-	   nread = 0; /* This is a distasteful hack, and we
-			 should replace that w/ something sane ASAP. It
-			 is here because none of the callers of readn()
-			 actually check for error condition, but in
-			 several places, the return value is assumed to
-			 be nonnegative. */
 	}
 
 	return nread;
@@ -1013,6 +1007,10 @@
 			int	newbytes;
 			memmove(inbuff, inbuff+ind, readbytes);
 			newbytes = readn(sock_fd, inbuff+readbytes, SOCKBUFF-readbytes);
+			if (newbytes < 0) {
+				fprintf(stderr, "Could not read from socket.\n");
+				return 0; /* Caller checks for != 1 */
+			}
 			filter_nonprintable(inbuff+readbytes, newbytes);
 			if (newbytes <= 0)
 				break;
@@ -1192,6 +1190,11 @@
 
 	/* read banner */
 	readbytes = readn(sock_fd, inbuff, sizeof(inbuff));
+	if (readbytes < 0) {
+		fprintf(stderr, "Could not read from socket\n");
+		retval = -1;
+		goto errout;
+	}
 
 	if (strncmp(inbuff, "200 ", 4) && strncmp(inbuff, "201 ", 4)) {
 		if(readbytes == sizeof(inbuff))
@@ -1276,6 +1279,11 @@
 	writen(sock_fd, "\n", 1);
 
 	readbytes = readn(sock_fd, inbuff, sizeof(inbuff));
+	if (readbytes < 0) {
+		fprintf(stderr, "Could not read from socket\n");
+		retval = -1;
+		goto errout;
+	}
 	if (strncmp(inbuff, "200 ", 4)) {
 		if(readbytes == sizeof(inbuff))
 			--readbytes;
@@ -1289,6 +1297,11 @@
 	/* enable new protocol variant. Weird command here, no cddb prefix ?!?! */
 	writen(sock_fd, "proto\n", 6);
 	readbytes = readn(sock_fd, inbuff, sizeof(inbuff));
+	if (readbytes < 0) {
+		fprintf(stderr, "Could not read from socket\n");
+		retval = -1;
+		goto errout;
+	}
 	/* check for errors and maximum supported protocol level */
 	if (strncmp(inbuff, "201 ", 4) > 0) {
 		if(readbytes == sizeof(inbuff))
@@ -1314,6 +1327,11 @@
 				sprintf(inbuff, "proto %1u\n", pr_level);
 				writen(sock_fd, inbuff, 8);
 				readbytes = readn(sock_fd, inbuff, sizeof(inbuff));
+				if (readbytes < 0) {
+					fprintf(stderr, "Could not read from socket\n");
+					retval = -1;
+					goto errout;
+				}
 				/* check for errors and maximum supported protocol level */
 				if (strncmp(inbuff, "201 ", 4) > 0) {
 					if(readbytes == sizeof(inbuff))
@@ -1366,6 +1384,11 @@
 	writen(sock_fd, outbuff, strlen(outbuff));
 
 	readbytes = readn(sock_fd, inbuff, sizeof(inbuff) - 1);
+	if (readbytes < 0) {
+		fprintf(stderr, "Could not read from socket\n");
+		retval = -1;
+		goto errout;
+	}
 	inbuff[readbytes] = '\0';
 	filter_nonprintable(inbuff, readbytes);
 	cat_offset = 4;
@@ -1423,6 +1446,11 @@
 
 	/* read status and first buffer size. */
 	readbytes = readn(sock_fd, inbuff, sizeof(inbuff));
+	if (readbytes < 0) {
+		fprintf(stderr, "Could not read from socket\n");
+		retval = -1;
+		goto errout;
+	}
 	filter_nonprintable(inbuff, readbytes);
 	if (strncmp(inbuff, "210 ", 4)) {
 		if(readbytes == sizeof(inbuff))
@@ -1441,6 +1469,11 @@
 	/* sign-off */
 	writen(sock_fd, "quit\n", 5);
 	readbytes = readn(sock_fd, inbuff, sizeof(inbuff));
+	if (readbytes < 0) {
+		fprintf(stderr, "Could not read from socket\n");
+		retval = -1;
+		goto errout;
+	}
 	if (strncmp(inbuff, "230 ", 4)) {
 		if(readbytes == sizeof(inbuff))
 			--readbytes;




More information about the Debburn-changes mailing list