Просмотр исходного кода

This patch checks the result of read operations on a socket which can
return errors or 0. Now if those cases happen, the operation is
ignored. This part of the code needs more attention later to handle
short reads. This removes a warning when fortify source is defined to
the compiler.


git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@1053 fd59a12c-fef9-0310-b244-a6a79926bd2f

Steven Dake 20 лет назад
Родитель
Сommit
7805cb474d
1 измененных файлов с 12 добавлено и 2 удалено
  1. 12 2
      lcr/uis.c

+ 12 - 2
lcr/uis.c

@@ -122,9 +122,19 @@ static void lcr_uis_dispatch (int fd)
 {
 	struct req_msg header;
 	char msg_contents[512];
+	ssize_t readsize;
 
-	read (fd, &header, sizeof (header));
-	read (fd, msg_contents, sizeof (msg_contents));
+	/*
+	 * TODO this doesn't handle short reads
+	 */
+	readsize = read (fd, &header, sizeof (header));
+	if (readsize == -1) {
+		return;
+	}
+	readsize = read (fd, msg_contents, sizeof (msg_contents));
+	if (readsize == -1) {
+		return;
+	}
 
 	printf ("msg contents %s\n", msg_contents);
 }