diff options
| author | Mattias Andrée <maandree@kth.se> | 2017-01-10 20:07:02 +0100 |
|---|---|---|
| committer | Mattias Andrée <maandree@kth.se> | 2017-01-10 20:07:02 +0100 |
| commit | 70158ed8bc74ce80a049c1beb71e85ae949778b2 (patch) | |
| tree | bcabd2964e2b07bf2eaa0aab10cd6dbe313fa6a4 /src/stream.c | |
| parent | Add vu-transpose (diff) | |
| download | blind-70158ed8bc74ce80a049c1beb71e85ae949778b2.tar.gz blind-70158ed8bc74ce80a049c1beb71e85ae949778b2.tar.bz2 blind-70158ed8bc74ce80a049c1beb71e85ae949778b2.tar.xz | |
Refuse infinite writes to regular files
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/stream.c')
| -rw-r--r-- | src/stream.c | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/src/stream.c b/src/stream.c index e99d003..cb487ad 100644 --- a/src/stream.c +++ b/src/stream.c @@ -2,18 +2,13 @@ #include "stream.h" #include "util.h" +#include <sys/stat.h> #include <errno.h> #include <stdlib.h> #include <string.h> #include <unistd.h> void -einit_stream(struct stream *stream) -{ - eninit_stream(1, stream); -} - -void eninit_stream(int status, struct stream *stream) { ssize_t r; @@ -104,12 +99,6 @@ set_pixel_size(struct stream *stream) } void -eset_pixel_size(struct stream *stream) -{ - enset_pixel_size(1, stream); -} - -void enset_pixel_size(int status, struct stream *stream) { if (set_pixel_size(stream)) @@ -126,12 +115,8 @@ fprint_stream_head(FILE *fp, struct stream *stream) } -size_t eread_stream(struct stream *stream, size_t n) -{ - return enread_stream(1, stream, n); -} - -size_t enread_stream(int status, struct stream *stream, size_t n) +size_t +enread_stream(int status, struct stream *stream, size_t n) { ssize_t r = read(stream->fd, stream->buf + stream->ptr, sizeof(stream->buf) - stream->ptr < n ? @@ -141,3 +126,14 @@ size_t enread_stream(int status, struct stream *stream, size_t n) stream->ptr += (size_t)r; return (size_t)r; } + + +void +eninf_check_fd(int status, int fd, const char *file) +{ + struct stat st; + if (fstat(fd, &st)) + eprintf("fstat %s:", file); + if (S_ISREG(st.st_mode)) + eprintf("%s is a regular file, refusing infinite write\n"); +} |
