diff options
author | default <nobody@localhost> | 2023-12-20 09:15:25 +0100 |
---|---|---|
committer | default <nobody@localhost> | 2023-12-20 09:15:25 +0100 |
commit | adcfc212c0561a972ff30c9d860d32874eb88d27 (patch) | |
tree | 48ad04889b66f29721bf8c5a2956e4ad30002117 /xs_fcgi.h | |
parent | 808849ba149fc2ccb579589c0d2f40351af3c777 (diff) |
Check some fwrite() return values in xs_fcgi_response().
Diffstat (limited to 'xs_fcgi.h')
-rw-r--r-- | xs_fcgi.h | 14 |
1 files changed, 8 insertions, 6 deletions
@@ -336,21 +336,23 @@ void xs_fcgi_response(FILE *f, int status, xs_dict *headers, xs_str *body, int b int offset = 0; while (offset < size) { - int sz = size - offset; + size_t sz = size - offset; if (sz > 0xffff) sz = 0xffff; hdr.content_len = htons(sz); - fwrite(&hdr, sizeof(hdr), 1, f); - fwrite(out + offset, 1, sz, f); + /* write or fail */ + if (!fwrite(&hdr, sizeof(hdr), 1, f) || fwrite(out + offset, 1, sz, f) != sz) + return; offset += sz; } /* final STDOUT packet with 0 size */ hdr.content_len = 0; - fwrite(&hdr, sizeof(hdr), 1, f); + if (!fwrite(&hdr, sizeof(hdr), 1, f)) + return; /* complete the connection */ ereq.app_status = 0; @@ -359,8 +361,8 @@ void xs_fcgi_response(FILE *f, int status, xs_dict *headers, xs_str *body, int b hdr.type = FCGI_END_REQUEST; hdr.content_len = htons(sizeof(ereq)); - fwrite(&hdr, sizeof(hdr), 1, f); - fwrite(&ereq, sizeof(ereq), 1, f); + if (fwrite(&hdr, sizeof(hdr), 1, f)) + fwrite(&ereq, sizeof(ereq), 1, f); } |