Ticket #2213 (closed defect: fixed)

Opened 6 years ago

Last modified 6 years ago

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

Changed 6 years ago by dmorissette

  • cc warmerdam, sdlime added
  • owner changed from sdlime to dmorissette

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

Changed 6 years ago by warmerdam

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

Changed 6 years ago by sdlime

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

Changed 6 years ago by dmorissette

  • status changed from new to assigned
  • milestone changed from 5.0 release to 5.2 release

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

Changed 6 years ago by dmorissette

  • status changed from assigned to closed
  • resolution set to fixed
  • milestone changed from 5.2 release to 5.0 release

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.