Opened 12 years ago

Last modified 11 years ago

#5115 new Patches

iostreams non_blocking_adapter read bug

Reported by: Mario Suvajac <msuvajac@…> Owned by: Jonathan Turkanis
Milestone: To Be Determined Component: iostreams
Version: Boost Development Trunk Severity: Showstopper
Keywords: non_blocking_adapter, read Cc:

Description

When reading from device resulting amount of read bytes is ignored.

line 31. of boost/iostreams/detail/adapter/non_blocking_adapter.hpp

     explicit non_blocking_adapter(Device& dev) : device_(dev) { }
     std::streamsize read(char_type* s, std::streamsize n)
     { 
         std::streamsize result = 0;
         while (result < n) {
-            std::streamsize amt = iostreams::read(device_, s, n);
+            std::streamsize amt = iostreams::read(device_, s, n - result);
             if (amt == -1)
                 break;
             result += amt;
         }
         return result != 0 ? result : -1;
     }

Attachments (2)

test.cpp (1.6 KB ) - added by msuvajac@… 11 years ago.
Buffer overwrite test case.
nb.diff (715 bytes ) - added by msuvajac@… 11 years ago.
Patch

Download all attachments as: .zip

Change History (5)

comment:1 by Mario Suvajac <msuvajac@…>, 12 years ago

actually, it should be:

-            std::streamsize amt = iostreams::read(device_, s, n);
+            std::streamsize amt = iostreams::read(device_, s + result, n - result);

by msuvajac@…, 11 years ago

Attachment: test.cpp added

Buffer overwrite test case.

by msuvajac@…, 11 years ago

Attachment: nb.diff added

Patch

comment:2 by msuvajac@…, 11 years ago

I've added a test case for this bug and a patch.

Also another issue for this adapter is if a device returns 0 as the amount read/written, that would cause a deadlock - endless loop.

comment:3 by msuvajac@…, 11 years ago

Type: BugsPatches
Note: See TracTickets for help on using tickets.