Skip to content

Commit 60d88c4

Browse files
authored
Merge pull request #4 from StevenChen8759/htstress
Fix invalid memory access during parsing URI
2 parents 8bb9015 + 0a3ba84 commit 60d88c4

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

htstress.c

+16-12
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,7 @@ static void init_conn(int efd, struct econn *ec)
152152
}
153153

154154
struct epoll_event evt = {
155-
.events = EPOLLOUT,
156-
.data.ptr = ec,
155+
.events = EPOLLOUT, .data.ptr = ec,
157156
};
158157

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

443444
if (strnlen(udaddr, sizeof(ssun->sun_path) - 1) == 0) {
@@ -487,9 +488,12 @@ int main(int argc, char *argv[])
487488
/* prepare request buffer */
488489
if (!host)
489490
host = node;
490-
outbufsize = strlen(rq) + sizeof(HTTP_REQUEST_FMT) + strlen(host);
491+
outbufsize = sizeof(HTTP_REQUEST_FMT) + strlen(host);
492+
outbufsize += rq ? strlen(rq) : 1;
493+
491494
outbuf = malloc(outbufsize);
492-
outbufsize = snprintf(outbuf, outbufsize, HTTP_REQUEST_FMT, rq, host);
495+
outbufsize =
496+
snprintf(outbuf, outbufsize, HTTP_REQUEST_FMT, rq ? rq : "/", host);
493497

494498
ticks = max_requests / 10;
495499

0 commit comments

Comments
 (0)