Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Fix incorrect calculation in shm_mq_receive.
authorRobert Haas <rhaas@postgresql.org>
Thu, 6 Aug 2015 17:25:45 +0000 (13:25 -0400)
committerRobert Haas <rhaas@postgresql.org>
Thu, 6 Aug 2015 17:36:10 +0000 (13:36 -0400)
If some, but not all, of the length word has already been read, and the
next attempt to read sees exactly the number of bytes needed to complete
the length word, or fewer, then we'll incorrectly read less than all of
the available data.

Antonin Houska

src/backend/storage/ipc/shm_mq.c

index d96627a774e9b000c04612de9f906057c8bcd561..a49bd17feeb09403c368fcea765e4dcf9f66ee3f 100644 (file)
@@ -488,7 +488,7 @@ shm_mq_receive(shm_mq_handle *mqh, Size *nbytesp, void **datap, bool nowait)
            if (mqh->mqh_partial_bytes + rb > sizeof(Size))
                lengthbytes = sizeof(Size) - mqh->mqh_partial_bytes;
            else
-               lengthbytes = rb - mqh->mqh_partial_bytes;
+               lengthbytes = rb;
            memcpy(&mqh->mqh_buffer[mqh->mqh_partial_bytes], rawdata,
                   lengthbytes);
            mqh->mqh_partial_bytes += lengthbytes;