Re: [PATCH; request for votes] snmplib: Avoid that sprint_realloc_octet_string() triggers a segmentation fault

Bart Van Assche <[email protected]>
Newsgroups gmane.network.net-snmp.devel
Message-ID <[email protected]>
On 05/19/18 15:14, Magnus Fromreide wrote:
> On Sat, May 19, 2018 at 02:07:56PM -0700, Bart Van Assche wrote:
>> strlcpy() implementations typically scan for the end of the source argument
>> passed to strlcpy(). Hence avoid passing an unterminated string to strlcpy().
>>
>> Reported-by: Stuart Henderson <[email protected]>
>> Fixes: 7f05daa8e0e0 ("CHANGES: BUG: 3444939: BUG: 1796886: snmplib: Avoid that sprint_realloc_octet_string() embeds unprintable control characters or binary zeroes in its output. This behavior could cause truncated output in snmptrapd.")
>> ---
>>   snmplib/mib.c | 5 +++--
>>   1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/snmplib/mib.c b/snmplib/mib.c
>> index a16144065029..1c875c06464f 100644
>> --- a/snmplib/mib.c
>> +++ b/snmplib/mib.c
>> @@ -585,9 +585,10 @@ sprint_realloc_octet_string(u_char ** buf, size_t * buf_len,
>>                               return 0;
>>                       }
>>                       if (memchr(cp, '\0', cnt) == NULL) {
>> -                        /* No embedded '\0' - use strlcpy() to preserve UTF-8 */
>> -                        strlcpy((char *)(*buf + *out_len), (char *)cp, cnt + 1);
>> +                        /* No embedded '\0' - use memcpy() to preserve UTF-8 */
> 
> The comment does not make any sense - what have UTF-8 got to do with this?

Hello Magnus,

Does this mean that you did not understand that comment? The code under 
the else-clause does not preserve UTF-8 (sprint_realloc_asciistring()). 
Hence the comment in the if-clause about preserving UTF-8.

Bart.


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.