commit adcfc21
default
·
2023-12-20 08:15:25 +0000 UTC
parent 808849b
Check some fwrite() return values in xs_fcgi_response().
1 files changed,
+8,
-6
+8,
-6
1@@ -336,21 +336,23 @@ void xs_fcgi_response(FILE *f, int status, xs_dict *headers, xs_str *body, int b
2 int offset = 0;
3
4 while (offset < size) {
5- int sz = size - offset;
6+ size_t sz = size - offset;
7 if (sz > 0xffff)
8 sz = 0xffff;
9
10 hdr.content_len = htons(sz);
11
12- fwrite(&hdr, sizeof(hdr), 1, f);
13- fwrite(out + offset, 1, sz, f);
14+ /* write or fail */
15+ if (!fwrite(&hdr, sizeof(hdr), 1, f) || fwrite(out + offset, 1, sz, f) != sz)
16+ return;
17
18 offset += sz;
19 }
20
21 /* final STDOUT packet with 0 size */
22 hdr.content_len = 0;
23- fwrite(&hdr, sizeof(hdr), 1, f);
24+ if (!fwrite(&hdr, sizeof(hdr), 1, f))
25+ return;
26
27 /* complete the connection */
28 ereq.app_status = 0;
29@@ -359,8 +361,8 @@ void xs_fcgi_response(FILE *f, int status, xs_dict *headers, xs_str *body, int b
30 hdr.type = FCGI_END_REQUEST;
31 hdr.content_len = htons(sizeof(ereq));
32
33- fwrite(&hdr, sizeof(hdr), 1, f);
34- fwrite(&ereq, sizeof(ereq), 1, f);
35+ if (fwrite(&hdr, sizeof(hdr), 1, f))
36+ fwrite(&ereq, sizeof(ereq), 1, f);
37 }
38
39