Commit Diff


commit - 71d196c9e2bffa978977785cd8859579e78bac24
commit + 895484c861438d44537d6b4ae700e7f16274565c
blob - 6937b7fc65d647d48188a0b45dee14132ef379f9
blob + aa4b34908402c0e2ee80c655f889cd5ff9e55664
--- lib/serve.c
+++ lib/serve.c
@@ -898,13 +898,36 @@ serve_read(int infd, int outfd, int gotd_sock, const c
 		if (err)
 			break;
 		if (n == 0) {
-			if (curstate != STATE_EXPECT_MORE_WANT &&
+			if (curstate != STATE_EXPECT_WANT &&
+			    curstate != STATE_EXPECT_MORE_WANT &&
 			    curstate != STATE_EXPECT_HAVE &&
 			    curstate != STATE_EXPECT_DONE) {
 				err = got_error_msg(GOT_ERR_BAD_PACKET,
 				    "unexpected flush packet received");
 				goto done;
 			}
+
+			if (curstate == STATE_EXPECT_WANT) {
+				ssize_t r;
+				/*
+				 * If the client does not want to fetch
+				 * anything we should receive a flush
+				 * packet followed by EOF.
+				 */
+				r = read(infd, buf, sizeof(buf));
+				if (r == -1) {
+					err = got_error_from_errno("read");
+					goto done;
+				}
+				if (r == 0) /* EOF */
+					goto done;
+
+				/* Zero-length field followed by payload. */
+				err = got_error_msg(GOT_ERR_BAD_PACKET,
+				    "unexpected flush packet received");
+				goto done;
+			}
+
 			err = forward_flushpkt(&ibuf);
 			if (err)
 				goto done;