Opened 17 years ago

Closed 17 years ago

#2213 closed defect (fixed)

msIO_printf() silently does nothing when output is larger than workbuf

Reported by: dmorissette Owned by: dmorissette
Priority: normal Milestone: 5.0 release
Component: MapServer C Library Version: svn-trunk (development)
Severity: normal Keywords:
Cc: warmerdam, sdlime

Description

While looking into ticket #1946, I found that msIO_printf() does not print anything and just silently returns -1 when the output is larger than the allocated workBuf[8000] (i.e. if vsnprintf returns a value larger than 8000).

Since calling code rarely checks the return value of printf calls, the user is never notified of the error. What would you think of adding a msSetError() call in this case? Even if the error is not trapped, it would show up in MS_ERRORFILE if it is enabled.

Change History (5)

comment:1 by dmorissette, 17 years ago

Cc: warmerdam sdlime added
Owner: changed from sdlime to dmorissette

I'll take this ticket but am interested in feedback from Frank and Steve.

comment:2 by warmerdam, 17 years ago

Daniel,

The CPLString::Printf() implementation shows a pattern for trying again on failure with a larger buffer. Be careful about the va_copy() stuff as if you get it wrong it will still work on some systems but not others.

http://trac.osgeo.org/gdal/browser/trunk/gdal/port/cplstring.cpp#L84

comment:3 by sdlime, 17 years ago

The effects of "silent" and very subtle bugs so I think any output that might help diagnose the problem. Are you proposing fixing the problem as Frank suggests or just writing to the error stack?

Steve

comment:4 by dmorissette, 17 years ago

Milestone: 5.0 release5.2 release
Status: newassigned

For 5.0 I have played safe and only added a msSetError() call before returning -1 in case of buffer overrun. That's in r6507. The error will be visible in the logs if MS_ERRORFILE is set.

We'll keep the real fix based on GDAL's CPLString::vPrintf() for v5.2

comment:5 by dmorissette, 17 years ago

Milestone: 5.2 release5.0 release
Resolution: fixed
Status: assignedclosed

Closing this ticket as fixed since the original issue was that msIO_printf() and family were silently returning -1 and now they call msSetError().

I have created ticket #2214 about rewriting the functions (in 5.2) to automatically try again with a larger buffer like CPLString::Printf() does.

Note: See TracTickets for help on using tickets.