diff --git a/src/duc/cmd-cgi.c b/src/duc/cmd-cgi.c index 7cd3f649..ae2fbe8d 100644 --- a/src/duc/cmd-cgi.c +++ b/src/duc/cmd-cgi.c @@ -257,9 +257,11 @@ static void include_file(const char *fname) printf("\n"); for(;;) { char buf[4096]; - size_t n = fread(buf, 1, sizeof(buf), f); - if(n == 0) break; - fwrite(buf, 1, n, stdout); + size_t in = fread(buf, 1, sizeof(buf), f); + if(in == 0) break; + size_t out = fwrite(buf, 1, in, stdout); + if(out == 0) break; + if(out < in) break; } printf("\n"); fclose(f); diff --git a/src/duc/main.c b/src/duc/main.c index 9a4906e3..287abfe5 100644 --- a/src/duc/main.c +++ b/src/duc/main.c @@ -211,6 +211,7 @@ static void printi(const char *s, int pos, int indent, int max) const char *p1 = s; const char *p2 = s; int i; + int out; while(*p1) { while(*p2 && !isspace(*p2)) p2++; @@ -222,7 +223,8 @@ static void printi(const char *s, int pos, int indent, int max) pos = indent; } - fwrite(p1, l, 1, stdout); + out = fwrite(p1, l, 1, stdout); + if (out == 0) break; while(*p2 && isspace(*p2)) p2++; pos += l; if(pos < max) { diff --git a/src/libduc-graph/graph-cairo.c b/src/libduc-graph/graph-cairo.c index 3e832793..3cce0198 100644 --- a/src/libduc-graph/graph-cairo.c +++ b/src/libduc-graph/graph-cairo.c @@ -41,7 +41,10 @@ struct cairo_backend_data { static cairo_status_t cairo_writer(void *closure, const unsigned char *data, unsigned int length) { FILE *f = closure; - fwrite(data, length, 1, f); + size_t out = fwrite(data, length, 1, f); + if (out == 0 || out < length) { + return CAIRO_STATUS_WRITE_ERROR; + } return CAIRO_STATUS_SUCCESS; }