Mercurial > dropbear
comparison fuzz/fuzz-wrapfd.c @ 1802:19b28d2fbe30
fuzz: handle errors from wrapfd_new_dummy()
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 06 Mar 2021 22:58:57 +0800 |
parents | 685b47d8faf7 |
children | 1b160ed94749 |
comparison
equal
deleted
inserted
replaced
1801:4983a6bc1f51 | 1802:19b28d2fbe30 |
---|---|
4 | 4 |
5 #include "dbutil.h" | 5 #include "dbutil.h" |
6 | 6 |
7 #include "fuzz.h" | 7 #include "fuzz.h" |
8 | 8 |
9 #define IOWRAP_MAXFD (FD_SETSIZE-1) | 9 // +100 might catch some limits... |
10 #define IOWRAP_MAXFD (FD_SETSIZE-1 + 100) | |
10 static const int MAX_RANDOM_IN = 50000; | 11 static const int MAX_RANDOM_IN = 50000; |
11 static const double CHANCE_CLOSE = 1.0 / 600; | 12 static const double CHANCE_CLOSE = 1.0 / 600; |
12 static const double CHANCE_INTR = 1.0 / 900; | 13 static const double CHANCE_INTR = 1.0 / 900; |
13 static const double CHANCE_READ1 = 0.96; | 14 static const double CHANCE_READ1 = 0.96; |
14 static const double CHANCE_READ2 = 0.5; | 15 static const double CHANCE_READ2 = 0.5; |
73 devnull_fd = open("/dev/null", O_RDONLY); | 74 devnull_fd = open("/dev/null", O_RDONLY); |
74 assert(devnull_fd != -1); | 75 assert(devnull_fd != -1); |
75 } | 76 } |
76 | 77 |
77 int fd = dup(devnull_fd); | 78 int fd = dup(devnull_fd); |
78 assert(fd != -1); | 79 if (fd == -1) { |
80 return -1; | |
81 } | |
82 if (fd > IOWRAP_MAXFD) { | |
83 close(fd); | |
84 errno = EMFILE; | |
85 return -1; | |
86 } | |
79 assert(wrap_fds[fd].mode == UNUSED); | 87 assert(wrap_fds[fd].mode == UNUSED); |
80 wrap_fds[fd].mode = DUMMY; | 88 wrap_fds[fd].mode = DUMMY; |
81 wrap_fds[fd].closein = 0; | 89 wrap_fds[fd].closein = 0; |
82 wrap_fds[fd].closeout = 0; | 90 wrap_fds[fd].closeout = 0; |
83 wrapfd_maxfd = MAX(fd, wrapfd_maxfd); | 91 wrapfd_maxfd = MAX(fd, wrapfd_maxfd); |
90 TRACE(("wrapfd_remove %d", fd)) | 98 TRACE(("wrapfd_remove %d", fd)) |
91 assert(fd >= 0); | 99 assert(fd >= 0); |
92 assert(fd <= IOWRAP_MAXFD); | 100 assert(fd <= IOWRAP_MAXFD); |
93 assert(wrap_fds[fd].mode != UNUSED); | 101 assert(wrap_fds[fd].mode != UNUSED); |
94 wrap_fds[fd].mode = UNUSED; | 102 wrap_fds[fd].mode = UNUSED; |
95 m_close(fd); | 103 close(fd); |
96 } | 104 } |
97 | 105 |
98 int wrapfd_close(int fd) { | 106 int wrapfd_close(int fd) { |
99 if (fd >= 0 && fd <= IOWRAP_MAXFD && wrap_fds[fd].mode != UNUSED) { | 107 if (fd >= 0 && fd <= IOWRAP_MAXFD && wrap_fds[fd].mode != UNUSED) { |
100 wrapfd_remove(fd); | 108 wrapfd_remove(fd); |