• Christophe JAILLET's avatar
    SUNRPC: Fix a potential buffer overflow in 'svc_print_xprts()' · b25b60d7
    Christophe JAILLET authored
    'maxlen' is the total size of the destination buffer. There is only one
    caller and this value is 256.
    
    When we compute the size already used and what we would like to add in
    the buffer, the trailling NULL character is not taken into account.
    However, this trailling character will be added by the 'strcat' once we
    have checked that we have enough place.
    
    So, there is a off-by-one issue and 1 byte of the stack could be
    erroneously overwridden.
    
    Take into account the trailling NULL, when checking if there is enough
    place in the destination buffer.
    
    
    While at it, also replace a 'sprintf' by a safer 'snprintf', check for
    output truncation and avoid a superfluous 'strlen'.
    
    Fixes: dc9a16e4 ("svc: Add /proc/sys/sunrpc/transport files")
    Signed-off-by: default avatarChristophe JAILLET <christophe.jaillet@wanadoo.fr>
    [ cel: very minor fix to documenting comment
    Signed-off-by: default avatarChuck Lever <chuck.lever@oracle.com>
    b25b60d7
svc_xprt.c 38.5 KB