[PATCH] lib/util: Add optional format argument to timeval_str_buf()

Martin Schwenke martin at meltin.net
Fri Oct 10 02:20:03 MDT 2014


On Fri, 10 Oct 2014 18:14:13 +1100, Martin Schwenke <martin at meltin.net>
wrote:

> On Thu, 9 Oct 2014 20:35:22 +0200, Volker Lendecke
> <Volker.Lendecke at SerNet.DE> wrote:
> 
> > On Thu, Oct 09, 2014 at 09:05:40PM +1100, Martin Schwenke wrote:
> > > > Hmm. Right now the timeval_str_buf function can be assumed to never fail,
> > > > because timeval_buf is large enough. If we now add a format argument,
> > > > it could easily overflow unnoticed. Is that what we want?
> > > 
> > > No.  Thanks for picking that up.  You'd have to be trying hard to
> > > overflow 128 byte of time string... but my code should have been
> > > better... :-)
> > > 
> > > I'd be happy if it truncated instead of overflowing.  However,
> > > strftime(3) doesn't provide such an option - it returns 0 and output
> > > is undefined on potential overflow.
> > 
> > What is your actual use case of this?
> 
> RFC5424-compatible timestamps:
> 
>   http://www.ietf.org/rfc/rfc5424.txt
> 
> This is to support syslog via UDP logging instead of the current CTDB
> log daemon.
> 
> Amitay and I came up a better way of doing this.  2 patches.  First
> changes timeval_str_buf() to use snprintf() instead of strftime(),
> since the latter is unnecessary - we're not using arbitrary formats
> anyway.  2nd adds an rfc5424 bool argument to timeval_str_buf() to allow
> it to produce the alternative timestamp format.  The changes are safe,
> since there's no arbitrary format, so no overflow...  :-)
> 
> Code is written, just need to test.  Will post patches soon...

Is this better?  :-)

peace & happiness,
martin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: samba.patches
Type: application/octet-stream
Size: 5624 bytes
Desc: not available
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20141010/1d8cfe09/attachment.obj>


More information about the samba-technical mailing list