Fix handling of oversize writes
authorAlex Bligh <alex@alex.org.uk>
Sat, 28 May 2011 18:29:20 +0000 (19:29 +0100)
committerAlex Bligh <alex@alex.org.uk>
Sat, 28 May 2011 18:29:20 +0000 (19:29 +0100)
Oversize writes were attempting to write the whole length of the
write each time, rather than BUFSIZ chunks. This could cause
disk corruption.

nbd-server.c

index 695deef..d57120b 100644 (file)
@@ -1568,7 +1568,7 @@ int mainloop(CLIENT *client) {
                                        consume(client->net, buf, len-currlen, BUFSIZE);
                                        continue;
                                }
                                        consume(client->net, buf, len-currlen, BUFSIZE);
                                        continue;
                                }
-                               if (expwrite(request.from, buf, len, client,
+                               if (expwrite(request.from, buf, currlen, client,
                                             request.type & NBD_CMD_FLAG_FUA)) {
                                        DEBUG("Write failed: %m" );
                                        ERROR(client, reply, errno);
                                             request.type & NBD_CMD_FLAG_FUA)) {
                                        DEBUG("Write failed: %m" );
                                        ERROR(client, reply, errno);