Commit Diff


commit - 0e10c6cfa04cb69c087f82ab141613adeb98e4f9
commit + c5331d4c606ecb36f1a7d62aa112cb094f93f5d4
blob - 445e57d5cea642f9e3bbc3562cd396ddb8f4442f
blob + 19c6f2218bdbfb4fbffb618c0f1c39e511a8717c
--- FICS/network.c
+++ FICS/network.c
@@ -337,6 +337,7 @@ PUBLIC int
 readline2(comstr_t *cs, int who)
 {
 	int			 bytes_received, state, fd, v_pending;
+	ssize_t			 ret;
 	static const uint8_t	 ayt[] = "[Responding to AYT: Yes, I'm here.]\n";
 	static const uint8_t	 will_sga[] = { IAC, WILL, TELOPT_SGA, '\0' };
 	static const uint8_t	 will_tm[] = { IAC, WILL, TELOPT_TM, '\0' };
@@ -354,8 +355,12 @@ readline2(comstr_t *cs, int who)
 	v_pending = con[who].numPending;
 	fd = con[who].fd;
 
-	if ((bytes_received = recv(fd, start + v_pending, MAX_STRING_LENGTH - 1 -
-	    v_pending, 0)) == 0) { // error: they've disconnected
+	ret = recv(fd, start + v_pending, MAX_STRING_LENGTH - 1 - v_pending, 0);
+	if (ret < INT_MIN || ret > INT_MAX)
+		errx(1, "%s: return out of bounds", __func__);
+	bytes_received = (int)ret;
+
+	if (bytes_received == 0) { // error: they've disconnected
 		return -1;
 	} else if (bytes_received == -1) {
 		if (errno != EWOULDBLOCK) { // some other error