Skip to content

Commit 12e2b53

Browse files
Fix NULL pointer access problem
Process with strchr() return NULL pointer case
1 parent 53ebfb5 commit 12e2b53

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

htstress.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,7 @@ static void init_conn(int efd, struct econn *ec)
151151
}
152152

153153
struct epoll_event evt = {
154-
.events = EPOLLOUT,
155-
.data.ptr = ec,
154+
.events = EPOLLOUT, .data.ptr = ec,
156155
};
157156

158157
if (epoll_ctl(efd, EPOLL_CTL_ADD, ec->fd, &evt)) {
@@ -429,14 +428,16 @@ int main(int argc, char *argv[])
429428
*rq++ = 0;
430429
port = rq;
431430
rq = strchr(rq, '/');
432-
if (*rq == '/') {
433-
port = strndup(port, rq - port);
434-
if (!port) {
435-
perror("port = strndup(rq, rq - port)");
436-
exit(EXIT_FAILURE);
437-
}
438-
} else
439-
rq = "/";
431+
if (rq) {
432+
if (*rq == '/') {
433+
port = strndup(port, rq - port);
434+
if (!port) {
435+
perror("port = strndup(rq, rq - port)");
436+
exit(EXIT_FAILURE);
437+
}
438+
} else
439+
rq = "/";
440+
}
440441
}
441442

442443
if (strnlen(udaddr, sizeof(ssun->sun_path) - 1) == 0) {

0 commit comments

Comments
 (0)