Fix oversize writes to write to correct area of disk
[nbd.git] / nbd-server.c
index 695deef..41b847a 100644 (file)
@@ -1568,7 +1568,7 @@ int mainloop(CLIENT *client) {
                                        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);
@@ -1576,6 +1576,7 @@ int mainloop(CLIENT *client) {
                                        continue;
                                }
                                len -= currlen;
+                               request.from += currlen;
                                currlen = (len < BUFSIZE) ? len : BUFSIZE;
                        }
                        SEND(client->net, reply);