Skip to content

Commit ecb3e3d

Browse files
committed
fixes to fio_http_body_read_until and fio_bstr_getdelim_fd
1 parent 9bfc853 commit ecb3e3d

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

fio-stl.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21258,7 +21258,7 @@ SFUNC int fio_string_getdelim_fd(fio_str_info_s *dest,
2125821258
return r;
2125921259
size_t index = fio_fd_find_next(fd, delim, (size_t)start_at);
2126021260
if (index == FIO_FD_FIND_EOF)
21261-
return r;
21261+
index = file_len;
2126221262
if (limit < 1 || limit > (index - start_at) + 1) {
2126321263
limit = (index - start_at) + 1;
2126421264
}
@@ -43634,12 +43634,16 @@ SFUNC fio_str_info_s fio_http_body_read_until(fio_http_s *h,
4363443634
char token,
4363543635
size_t limit) {
4363643636
fio_str_info_s r = {0};
43637-
if (h->body.pos == h->body.len)
43637+
if (h->body.pos >= h->body.len)
4363843638
return r;
43639-
if (!limit || (h->body.pos + limit) > h->body.len)
43639+
if (!limit || limit > h->body.len || limit > (h->body.len - h->body.pos))
4364043640
limit = h->body.len - h->body.pos;
43641+
if (!limit)
43642+
return r;
4364143643
r = ((h->body.fd == -1) ? fio___http_body_read_until_buf
4364243644
: fio___http_body_read_until_fd)(h, token, limit);
43645+
if (!r.len)
43646+
r.buf = NULL;
4364343647
return r;
4364443648
}
4364543649

@@ -48379,6 +48383,9 @@ FIO_SFUNC void fio__http_controller_on_destroyed_client(fio_http_s *h) {
4837948383
fio_http_cdata(h));
4838048384
fio___http_connection_s *c = (fio___http_connection_s *)fio_http_cdata(h);
4838148385
c->state.http.on_finish(h);
48386+
if (c->state.http.buf.buf)
48387+
FIO_STRING_FREE2(c->state.http.buf);
48388+
c->state.http.buf = FIO_STR_INFO0;
4838248389
c->h = NULL;
4838348390
if (c->io)
4838448391
fio_io_close(c->io);

fio-stl/102 string core.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2838,7 +2838,7 @@ SFUNC int fio_string_getdelim_fd(fio_str_info_s *dest,
28382838
return r;
28392839
size_t index = fio_fd_find_next(fd, delim, (size_t)start_at);
28402840
if (index == FIO_FD_FIND_EOF)
2841-
return r;
2841+
index = file_len;
28422842
if (limit < 1 || limit > (index - start_at) + 1) {
28432843
limit = (index - start_at) + 1;
28442844
}

fio-stl/431 http handle.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2309,12 +2309,16 @@ SFUNC fio_str_info_s fio_http_body_read_until(fio_http_s *h,
23092309
char token,
23102310
size_t limit) {
23112311
fio_str_info_s r = {0};
2312-
if (h->body.pos == h->body.len)
2312+
if (h->body.pos >= h->body.len)
23132313
return r;
2314-
if (!limit || (h->body.pos + limit) > h->body.len)
2314+
if (!limit || limit > h->body.len || limit > (h->body.len - h->body.pos))
23152315
limit = h->body.len - h->body.pos;
2316+
if (!limit)
2317+
return r;
23162318
r = ((h->body.fd == -1) ? fio___http_body_read_until_buf
23172319
: fio___http_body_read_until_fd)(h, token, limit);
2320+
if (!r.len)
2321+
r.buf = NULL;
23182322
return r;
23192323
}
23202324

fio-stl/439 http.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2392,6 +2392,9 @@ FIO_SFUNC void fio__http_controller_on_destroyed_client(fio_http_s *h) {
23922392
fio_http_cdata(h));
23932393
fio___http_connection_s *c = (fio___http_connection_s *)fio_http_cdata(h);
23942394
c->state.http.on_finish(h);
2395+
if (c->state.http.buf.buf)
2396+
FIO_STRING_FREE2(c->state.http.buf);
2397+
c->state.http.buf = FIO_STR_INFO0;
23952398
c->h = NULL;
23962399
if (c->io)
23972400
fio_io_close(c->io);

0 commit comments

Comments
 (0)