Skip to content

C file reading is implemented incorrectly #530

@nh2

Description

@nh2

The project does not check for short read()s.

In C, as per man 2 read, it returns the number of Bytes read:

It is not an error if this number is smaller than the number of bytes requested; this may happen for example because fewer bytes are actually available right now

Thus you need to loop around read(), always.

Relevant code

i3status/src/general.c

Lines 34 to 37 in 200fef9

/* We need one byte for the trailing 0 byte */
int n = read(fd, destination, size - 1);
if (n != -1)
destination[n] = '\0';

n = read(fd, buf, ctx->max_chars);

This is wrong since 15 years ago:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions