Opened 15 years ago

Closed 15 years ago

#3973 closed bug (fixed)

ioctl FIONREAD does not propagate errors

Reported by: titer Owned by: mmlr
Priority: normal Milestone: R1
Component: Network & Internet Version: R1/pre-alpha1
Keywords: Cc:
Blocked By: Blocking:
Platform: All

Description

Test case with a not connected socket:

#include <stdio.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/socket.h>

int main()
{
    int fd = socket(AF_INET, SOCK_STREAM, 0);
    int n = 0x42;
    int ret = ioctl(fd, FIONREAD, &n);
    printf("ret %d, n %d / %X\n", ret, n, n);
    return 0;
}

gives:

ret 0, n -2147454946 / 8000701E

The ioctl should return -1 and set errno, rather than saying there are ENOTCONN bytes available for reading.

I noticed this from running libevent tests - since ioctl returns 0, it (legitimately IMO) assumes the value is >= 0 and ends up trying to allocate some GBs of memory.

Haiku hrev30805 gcc4

Change History (2)

comment:1 by mmlr, 15 years ago

Owner: changed from axeld to mmlr
Status: newassigned

Looking into it.

comment:2 by mmlr, 15 years ago

Resolution: fixed
Status: assignedclosed

Fixed in hrev30896.

Note: See TracTickets for help on using tickets.