Menu

#1127 Resize large fd sets to the same size before calling select

closed
nobody
None
5
2012-11-09
2011-03-09
Santanu
No

Currently, the large-fd-set buffers passed to select() in the receive() function could be of variable sizes. Some of them may even have a lesser size than the 'numfds' passed to select. Consider the following scenario -

read-fd-set = {2000, 2001}
write-fd-set = {10}
except-fd-set = {5}
numfds = 2002

On a Linux platform the write and except fd set buffer sizes for the above case will be 1024. This will cause 'select()' to examine past the buffer bounds for write and except fd sets.

This patch provides a wrapper for the select() call, viz net_snmp_large_select(). This function resizes the read, write and except large_fd_set-s to the maximum fd-set size of the three before passing them to select().

Also, a wrong boundary calculation has been rectified while clearing the resized area of large fd sets.

The patch is tested on ucd-snmp-4.2 having a backport of the large-fd-set feature on Linux systems running on ppc32 and i586 processors. The problem exists even in net-snmp-5.6.1. The patch provided is applicable to net-snmp-5.6.1.

Discussion

  • Santanu

    Santanu - 2011-03-09

    Patch: resizes large fd sets to the max of the three sizes before select

     
  • Bart Van Assche

    Bart Van Assche - 2011-03-10

    While the net_snmp_large_select() function in the attached patch is interesting, I still a few issues that make it not yet ready for general use (outside receive()):
    - The case where one or more of the fds pointers is NULL is not handled.
    - If numfds > max_setsize, it is still possible that memory corruption is triggered by invoking net_snmp_large_select().

    A modified version of this patch (that addresses the above two points) has been applied on the trunk and the V5.6 branch as r20105, r20108, r20109 and r20110 - thanks for the patch.

    Please review these four commits.

     
  • Santanu

    Santanu - 2011-03-16

    The commits look fine to me. Thanks.

     

Log in to post a comment.