[OPEN-ILS-DEV] Re: PATCH: bzero is deprecated and unnecessary

Mike Rylander mrylander at gmail.com
Sun Sep 30 17:57:24 EDT 2007


On 9/30/07, Mike Rylander <mrylander at gmail.com> wrote:

[snip]

>
> I'm going to work up a patch that implements Scott's suggested buffer
> misuse detector and replaces all memsets with that.  Any
> objections/suggestions?

And here it is.  In its current form it

1) creates the suggested safe_calloc which includes memset

2) creates a macro called osrf_clearbuf which

  * Under NDEBUG fills the buffer with !s and a trailing nul
  * otherwise (currently) uses memset to fill with nuls

The secondary behavior should be changed to a no-op after no more
problems arise under NDEBUG mode.  I reversed the suggested semantics
because I'm not ready to completely break trunk.

The macro, as created, differs from the suggested in that it does not
create temp vars for s and n.  The compiler was not at all happy about
the void casting for some reason, so I just act on the buffer (s)
passed.

3) replaces all memsets (excepting the ones in safe_?alloc) that act
on char bufs with said macro, so they can be spotted and improved to
deal with nul terminators where needed.  I didn't touch any memsets on
struct pointers.

4) made jid_get_*() from src/libopensrf/transport_message.c safe for
use with NDEBUG mode.  They were depending on the target buffer that
the caller passes in to be nul-filled (they use strncpy/memcpy which
don't guarantee terminal nul) -- now they provide their own terminal
nul.

As a side note, I did notice one use of safe_malloc for allocating a
string buffer.  I left it untouched, but wanted to mention it.

I'll wait for comments before applying.

-- 
Mike Rylander
 | VP, Research and Design
 | Equinox Software, Inc. / The Evergreen Experts
 | phone:  1-877-OPEN-ILS (673-6457)
 | email:  miker at esilibrary.com
 | web:  http://www.esilibrary.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: osrf_clearbuf-mem-audit-framework.patch
Type: text/x-diff
Size: 10562 bytes
Desc: not available
Url : http://list.georgialibraries.org/pipermail/open-ils-dev/attachments/20070930/4c936150/osrf_clearbuf-mem-audit-framework.bin


More information about the Open-ils-dev mailing list