summaryrefslogtreecommitdiff
path: root/xs_fcgi.h
diff options
context:
space:
mode:
authorGravatar default2023-12-20 09:15:25 +0100
committerGravatar default2023-12-20 09:15:25 +0100
commitadcfc212c0561a972ff30c9d860d32874eb88d27 (patch)
tree48ad04889b66f29721bf8c5a2956e4ad30002117 /xs_fcgi.h
parentDon't collect our own shared inbox. (diff)
downloadsnac2-adcfc212c0561a972ff30c9d860d32874eb88d27.tar.gz
snac2-adcfc212c0561a972ff30c9d860d32874eb88d27.tar.xz
snac2-adcfc212c0561a972ff30c9d860d32874eb88d27.zip
Check some fwrite() return values in xs_fcgi_response().
Diffstat (limited to 'xs_fcgi.h')
-rw-r--r--xs_fcgi.h14
1 files changed, 8 insertions, 6 deletions
diff --git a/xs_fcgi.h b/xs_fcgi.h
index 50115b1..a7b766f 100644
--- a/xs_fcgi.h
+++ b/xs_fcgi.h
@@ -336,21 +336,23 @@ void xs_fcgi_response(FILE *f, int status, xs_dict *headers, xs_str *body, int b
336 int offset = 0; 336 int offset = 0;
337 337
338 while (offset < size) { 338 while (offset < size) {
339 int sz = size - offset; 339 size_t sz = size - offset;
340 if (sz > 0xffff) 340 if (sz > 0xffff)
341 sz = 0xffff; 341 sz = 0xffff;
342 342
343 hdr.content_len = htons(sz); 343 hdr.content_len = htons(sz);
344 344
345 fwrite(&hdr, sizeof(hdr), 1, f); 345 /* write or fail */
346 fwrite(out + offset, 1, sz, f); 346 if (!fwrite(&hdr, sizeof(hdr), 1, f) || fwrite(out + offset, 1, sz, f) != sz)
347 return;
347 348
348 offset += sz; 349 offset += sz;
349 } 350 }
350 351
351 /* final STDOUT packet with 0 size */ 352 /* final STDOUT packet with 0 size */
352 hdr.content_len = 0; 353 hdr.content_len = 0;
353 fwrite(&hdr, sizeof(hdr), 1, f); 354 if (!fwrite(&hdr, sizeof(hdr), 1, f))
355 return;
354 356
355 /* complete the connection */ 357 /* complete the connection */
356 ereq.app_status = 0; 358 ereq.app_status = 0;
@@ -359,8 +361,8 @@ void xs_fcgi_response(FILE *f, int status, xs_dict *headers, xs_str *body, int b
359 hdr.type = FCGI_END_REQUEST; 361 hdr.type = FCGI_END_REQUEST;
360 hdr.content_len = htons(sizeof(ereq)); 362 hdr.content_len = htons(sizeof(ereq));
361 363
362 fwrite(&hdr, sizeof(hdr), 1, f); 364 if (fwrite(&hdr, sizeof(hdr), 1, f))
363 fwrite(&ereq, sizeof(ereq), 1, f); 365 fwrite(&ereq, sizeof(ereq), 1, f);
364} 366}
365 367
366 368