mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-25 14:35:04 +00:00
Check some fwrite() return values in xs_fcgi_response().
This commit is contained in:
parent
808849ba14
commit
adcfc212c0
1 changed files with 8 additions and 6 deletions
12
xs_fcgi.h
12
xs_fcgi.h
|
@ -336,21 +336,23 @@ void xs_fcgi_response(FILE *f, int status, xs_dict *headers, xs_str *body, int b
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
|
|
||||||
while (offset < size) {
|
while (offset < size) {
|
||||||
int sz = size - offset;
|
size_t sz = size - offset;
|
||||||
if (sz > 0xffff)
|
if (sz > 0xffff)
|
||||||
sz = 0xffff;
|
sz = 0xffff;
|
||||||
|
|
||||||
hdr.content_len = htons(sz);
|
hdr.content_len = htons(sz);
|
||||||
|
|
||||||
fwrite(&hdr, sizeof(hdr), 1, f);
|
/* write or fail */
|
||||||
fwrite(out + offset, 1, sz, f);
|
if (!fwrite(&hdr, sizeof(hdr), 1, f) || fwrite(out + offset, 1, sz, f) != sz)
|
||||||
|
return;
|
||||||
|
|
||||||
offset += sz;
|
offset += sz;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* final STDOUT packet with 0 size */
|
/* final STDOUT packet with 0 size */
|
||||||
hdr.content_len = 0;
|
hdr.content_len = 0;
|
||||||
fwrite(&hdr, sizeof(hdr), 1, f);
|
if (!fwrite(&hdr, sizeof(hdr), 1, f))
|
||||||
|
return;
|
||||||
|
|
||||||
/* complete the connection */
|
/* complete the connection */
|
||||||
ereq.app_status = 0;
|
ereq.app_status = 0;
|
||||||
|
@ -359,7 +361,7 @@ void xs_fcgi_response(FILE *f, int status, xs_dict *headers, xs_str *body, int b
|
||||||
hdr.type = FCGI_END_REQUEST;
|
hdr.type = FCGI_END_REQUEST;
|
||||||
hdr.content_len = htons(sizeof(ereq));
|
hdr.content_len = htons(sizeof(ereq));
|
||||||
|
|
||||||
fwrite(&hdr, sizeof(hdr), 1, f);
|
if (fwrite(&hdr, sizeof(hdr), 1, f))
|
||||||
fwrite(&ereq, sizeof(ereq), 1, f);
|
fwrite(&ereq, sizeof(ereq), 1, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue