[BusyBox] bug in cut in 0.60.2
Foley, Brian (Galway)
Brian.P.Foley at compaq.com
Tue Feb 26 08:04:06 UTC 2002
Hi all,
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
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 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'?
Cheers,
Brian Foley.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cut.diff
Type: application/octet-stream
Size: 438 bytes
Desc: cut.diff
Url : http://lists.busybox.net/pipermail/busybox/attachments/20020226/e2ae74d9/attachment.obj
More information about the busybox
mailing list