fix potential overflow in nfs_pread_mcb
authorPeter Lieven <pl@kamp.de>
Sat, 15 Mar 2014 13:20:29 +0000 (14:20 +0100)
committerPeter Lieven <pl@kamp.de>
Sun, 16 Mar 2014 19:07:39 +0000 (20:07 +0100)
Signed-off-by: Peter Lieven <pl@kamp.de>
lib/libnfs.c

index 7946f2ffca1a317a0a468cf5fa7835f0b5bb93ff..4f0650f41abbe9ccca78bfc7a01fece238b9e706 100644 (file)
@@ -1588,9 +1588,14 @@ static void nfs_pread_mcb(struct rpc_context *rpc, int status, void *command_dat
                        data->error = 1;
                } else  {
                        if (res->READ3res_u.resok.count > 0) {
-                               memcpy(&data->buffer[mdata->offset - data->start_offset], res->READ3res_u.resok.data.data_val, res->READ3res_u.resok.count);
-                               if ((unsigned)data->max_offset < mdata->offset + res->READ3res_u.resok.count) {
-                                       data->max_offset = mdata->offset + res->READ3res_u.resok.count;
+                               if (res->READ3res_u.resok.count <= mdata->count) {
+                                       memcpy(&data->buffer[mdata->offset - data->start_offset], res->READ3res_u.resok.data.data_val, res->READ3res_u.resok.count);
+                                       if ((unsigned)data->max_offset < mdata->offset + res->READ3res_u.resok.count) {
+                                               data->max_offset = mdata->offset + res->READ3res_u.resok.count;
+                                       }
+                               } else {
+                                       rpc_set_error(nfs->rpc, "NFS: Read overflow. Server has sent more data than requested!");
+                                       data->error = 1;
                                }
                        }
                }