[BusyBox] Bug in busybox cp copy_file_chunk.

Brenk, Rudger van rudger.van.brenk at intersil.com
Thu May 31 06:19:46 UTC 2001


Hi Erik,

I've found a bug in busybox copy app. When my JFFS returns an error code (such
as -28 no space left on device) the cp app will keep on trying to copy this
chunk to the flash. The full write function will return -28 but this return code
is tested against the size_t size (size_t is defined as unsigned long int). For
all negative codes this will fail.

Since full_write will only return size or the error code this line can be
changed in if (full_write(......,....) < 0) return FALSE;

Original:
int copy_file_chunk(int srcfd, int dstfd, off_t chunksize)
{
        off_t size;
        char buffer[BUFSIZ]; /* BUFSIZ is declared in stdio.h */

        while (chunksize > 0) {
                if (chunksize > BUFSIZ)
                        size = BUFSIZ;
                else
                        size = chunksize;
                if (full_write(dstfd, buffer, full_read(srcfd, buffer, size)) <
size)
                        return(FALSE);
                chunksize -= size;
        }
        return (TRUE);
}
changed:
int copy_file_chunk(int srcfd, int dstfd, off_t chunksize)
{
        off_t size;
        char buffer[BUFSIZ]; /* BUFSIZ is declared in stdio.h */

        while (chunksize > 0) {
                if (chunksize > BUFSIZ)
                        size = BUFSIZ;
                else
                        size = chunksize;
                if (full_write(dstfd, buffer, full_read(srcfd, buffer, size)) <
0)
                        return(FALSE);
                chunksize -= size;
        }
        return (TRUE);
}

Greetings,

Rudger van Brenk.

Intersil BV
PO Box 343
3720 AH Bilthoven
The Netherlands

Rembrandtlaan 1a
3723 BG Bilthoven
The Netherlands

Tel: +31 30 225 97 40
Fax: +31 30 229 60 61

Rudger.van.Brenk at intersil.com







More information about the busybox mailing list