Skip to content

The issue about fnctl that can returb -1 on failure #128

Open

Description

@robang74

There is an issue in libbb/xfuncs.c when we consider that -1 is 0xFF...FF:

#include "libbb.h"

/* Turn on nonblocking I/O on a fd */
int FAST_FUNC ndelay_on(int fd)
{
    int flags = fcntl(fd, F_GETFL);
    if (flags & O_NONBLOCK)
        return flags;
    fcntl(fd, F_SETFL, flags | O_NONBLOCK);
    return flags;
}

int FAST_FUNC ndelay_off(int fd)
{
    int flags = fcntl(fd, F_GETFL);
    if (!(flags & O_NONBLOCK))
        return flags;
    fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
    return flags;
}

The fcntl() can return -1 in case of error and -1 has ALL the bits up and whatever the flag is found.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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