[BusyBox] bug in cut in 0.60.2

Matt Kraai kraai at alumni.cmu.edu
Tue Feb 26 08:30:03 UTC 2002


On Tue, Feb 26, 2002 at 03:02:08PM -0000, Foley, Brian (Galway) wrote:
> There's a small bug in the cut applet in busybox-0.60.2 when dealing with empty lines and the -c option.
> 
> To show it up, try something like the following:
> 
> echo | ./busybox cut -c42 
> 
> You get the output:
> cut: memory exhausted

I don't see this error.  My libc must be returning a non-NULL
value for zero-length allocations.

> The problem occurs in cut_line_by_chars. A buffer (*printed) is allocated using xcalloc, and if we try to allocate 0 bytes, xcalloc exits and prints an error.
> 
> I've included a simple patch that fixes this by making sure we allocate at least 1 byte for the buffer.

This is bogus.  We should fix xcalloc instead.

> This brings up a question though: How should xcalloc handle the case when one or both of its arguments are 0? Should it just return NULL? Or should it die with the misleading error 'memory exhausted'?

It should return NULL.  That is legal if the requested buffer size
is 0.  I've fixed this in CVS.

Matt
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: not available
Url : http://lists.busybox.net/pipermail/busybox/attachments/20020226/4da7e629/attachment.pgp 


More information about the busybox mailing list