ljvblfz / unyaffs

Automatically exported from code.google.com/p/unyaffs
0 stars 0 forks source link

read and write should be allowed to return less than specified #4

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
The code assumes that read and write will read and write according to their
specified third argument.

I haven't written C in over 10 years, but I believe that not handling
properly the return value of read and write is a bug.

So

    } else if ((s == (CHUNK_SIZE + SPARE_SIZE))) {
        } else {
        fprintf(stderr, "broken image file\n");

is probably wrong. The image file isn't broken. The reading just didn't
read enough characters and

            if (write(out_file, chunk_data, s) == -1)
                return -1;
            remain -= s;

1. assumes we read s characters,
2. doesn't consider if some characters weren't written.

The attached patch also contains
* the --help option has found in issue #3 (patch is improved as we don't
used strncmp otherwise we match --helpWHATEVER_COMES_AFTER
* a new --verbose option
* a tentative fix for this potential issue

Original issue reported on code.google.com by jerome.l...@gmail.com on 4 May 2009 at 11:56

Attachments:

GoogleCodeExporter commented 8 years ago
New patch, same as above + with --dry_run option.

Original comment by jerome.l...@gmail.com on 5 May 2009 at 12:03

Attachments: