]> andersk Git - moira.git/commitdiff
distinguish read errors from incomplete reads. (in the incomplete case,
authordanw <danw>
Tue, 21 Sep 1999 17:29:57 +0000 (17:29 +0000)
committerdanw <danw>
Tue, 21 Sep 1999 17:29:57 +0000 (17:29 +0000)
don't return errno, since it may be 0. return EIO instead.) Fixes a bug
where update_test could core dump if the remote server closed the
connection unexpectedly (because of a bug on their end).

update/sendrecv.c

index 888941d976f658a34403d2b820166fbaed89b10b..f82dc90f48aa9d86e35d9ff9c61f2e66fbaed590 100644 (file)
@@ -42,12 +42,19 @@ int send_int(int conn, long data)
 int recv_int(int conn, long *data)
 {
   char buf[8];
+  int len;
 
-  if (read(conn, buf, 8) != 8)
+  len = read(conn, buf, 8);
+  if (len == -1)
     {
       fail(conn, errno, "reading integer");
       return errno;
     }
+  else if (len < 8)
+    {
+      fail(conn, 0, "remote connection closed while reading integer");
+      return EIO;
+    }
   getlong((buf + 4), *data);
   return 0;
 }
@@ -81,16 +88,29 @@ int recv_string(int conn, char **buf, size_t *len)
   char tmp[4];
   int size, more;
 
-  if (read(conn, tmp, 4) != 4)
+  size = read(conn, tmp, 4);
+  if (size == -1)
     {
       fail(conn, errno, "reading string");
       return errno;
     }
-  if (read(conn, tmp, 4) != 4)
+  else if (size < 4)
+    {
+      fail(conn, 0, "remote connection closed while reading string");
+      return EIO;
+    }
+
+  size = read(conn, tmp, 4);
+  if (size == -1)
     {
       fail(conn, errno, "reading string");
       return errno;
     }
+  else if (size < 4)
+    {
+      fail(conn, 0, "remote connection closed while reading string");
+      return EIO;
+    }
   getlong(tmp, *len);
 
   *buf = malloc(*len);
This page took 0.600652 seconds and 5 git commands to generate.