SB-BSD-SOCKETS:SOCKET-RECEIVE throws an error when there are more bytes to read than will fit in the buffer

Bug #1023438 reported by eadmund
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Fix Released
Undecided
Unassigned

Bug Description

SB-BSD-SOCKETS:SOCKET-RECEIVE's interface specifies that it will read only as many bytes as are requested; this is not in fact the case, at least with a UDP socket. It sets MSG_TRUNC for all UDP receives, which means that the length LEN returned by RECVFROM will be the total packet length, not the requested data length LENGTH. Then it attempts to copy LEN, not LENGTH, bytes into BUFFER, resulting in an exception if BUFFER is shorter than LEN. If instead of (loop for i from 0 below len ...) it used (loop for i from 0 below (min len length)...) then all would be well.

Of note, even if BUFFER is large enough to hold LEN bytes, it is a violation of the interface to write more data than requested into it.

Revision history for this message
eadmund (eadmund) wrote :
Revision history for this message
Stas Boukarev (stassats) wrote :

commit 9d17f7daef6d930a229ae6c0339c9eefc3dd71e6
Author: Nathan Froyd <email address hidden>
Date: Tue Sep 4 22:45:03 2012 -0400

    make SOCKET-RECEIVE work correctly when receiving overly-long UDP packets

    Only copy as much data as the provided buffer can hold. Continue to return
    the length provided from recvfrom as per documentation.

Changed in sbcl:
status: New → Fix Committed
Changed in sbcl:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.