<<< Date Index >>>     <<< Thread Index >>>

imap/2376: IMAP fails on platforms with non-C99 vsnprintf(3)



>Number:         2376
>Notify-List:    
>Category:       imap
>Synopsis:       IMAP fails on platforms with non-C99 vsnprintf(3)
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    mutt-dev
>State:          open
>Keywords:       
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Jul 23 04:22:26 +0200 2006
>Originator:     Holger Weiss
>Release:        1.5.12
>Organization:
Freie Universitaet Berlin
>Environment:
IRIX64 6.5.28f
>Description:
When using IMAP on IRIX (and possibly other platforms), Mutt 1.5.12 hangs 
forever while "Fetching message headers...".  This happens because longer IMAP 
commands are truncated to 127 characters prior to sending them; whereupon Mutt 
will wait forever for the server response to the incomplete command.

The truncation occurs because, in order to calculate the necessary size of the 
buffer holding the IMAP command, mutt_buffer_printf() relies on vsnprintf(3) 
returning the number of characters which _would_ have been written to a 
sufficiently sized buffer, see muttlib.c:1438.  However, (at least) on IRIX, 
vsnprintf(3) returns the actual length of the output string, which leads to 
mutt_buffer_printf() not recognizing that the size of the buffer in question 
would have to be increased.  Instead, the IMAP command is truncated to fit into 
the (default) buffer size of 128.

Apart from that, the [v]snprintf(3) replacement functions provided in 
snprintf.c return the length of the actual output string just as the IRIX 
implementation does, so without modification, they cannot be used either.

Of course, the [v]snprintf(3) problem might also arise elsewhere in the code, I 
haven't checked.
>How-To-Repeat:
Try to use IMAP on IRIX.
>Fix:
The attached patch fixes the return value of the replacement functions in 
snprintf.c and changes configure.in so that the replacements are used if the 
system's [v]snprintf(3) implementation doesn't return the correct length (or if 
it doesn't truncate the output appropriately, which happened on Solaris 7 IIRC).
>Add-To-Audit-Trail:

>Unformatted:
 ----gnatsweb-attachment----
 Content-Type: application/octet-stream; name="c99_vsnprintf.diff"
 Content-Transfer-Encoding: base64
 Content-Disposition: attachment; filename="c99_vsnprintf.diff"
 
 SW5kZXg6IGNvbmZpZ3VyZS5pbgo9PT09PT09PT09PT09PT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