diff options
author | Renato Botelho <renato@netgate.com> | 2016-05-09 17:39:11 -0300 |
---|---|---|
committer | Renato Botelho <renato@netgate.com> | 2016-05-09 17:39:11 -0300 |
commit | eb1aa95459d780e1328d821fd6af261c2221a62b (patch) | |
tree | d0c75db0de1902022252ffee3acbfe775366214c /contrib/file/src/magic.c | |
parent | 4a578420216361b8acfb7296dd0b68c805e5121b (diff) | |
parent | 1708fafa25d9413ab466d3670d803e2ebf885d45 (diff) | |
download | FreeBSD-src-eb1aa95459d780e1328d821fd6af261c2221a62b.zip FreeBSD-src-eb1aa95459d780e1328d821fd6af261c2221a62b.tar.gz |
Merge remote-tracking branch 'origin/stable/10' into devel
Diffstat (limited to 'contrib/file/src/magic.c')
-rw-r--r-- | contrib/file/src/magic.c | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/contrib/file/src/magic.c b/contrib/file/src/magic.c index 315a944..87ac1cb 100644 --- a/contrib/file/src/magic.c +++ b/contrib/file/src/magic.c @@ -33,7 +33,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: magic.c,v 1.97 2016/03/31 17:51:12 christos Exp $") +FILE_RCSID("@(#)$File: magic.c,v 1.95 2015/09/11 17:24:09 christos Exp $") #endif /* lint */ #include "magic.h" @@ -346,7 +346,7 @@ private void close_and_restore(const struct magic_set *ms, const char *name, int fd, const struct stat *sb) { - if (name == NULL) + if (fd == STDIN_FILENO || name == NULL) return; (void) close(fd); @@ -417,7 +417,7 @@ file_or_fd(struct magic_set *ms, const char *inname, int fd) * some overlapping space for matches near EOF */ #define SLOP (1 + sizeof(union VALUETYPE)) - if ((buf = CAST(unsigned char *, malloc(ms->bytes_max + SLOP))) == NULL) + if ((buf = CAST(unsigned char *, malloc(HOWMANY + SLOP))) == NULL) return NULL; switch (file_fsmagic(ms, inname, &sb)) { @@ -481,13 +481,13 @@ file_or_fd(struct magic_set *ms, const char *inname, int fd) } /* - * try looking at the first ms->bytes_max bytes + * try looking at the first HOWMANY bytes */ if (ispipe) { ssize_t r = 0; while ((r = sread(fd, (void *)&buf[nbytes], - (size_t)(ms->bytes_max - nbytes), 1)) > 0) { + (size_t)(HOWMANY - nbytes), 1)) > 0) { nbytes += r; if (r < PIPE_BUF) break; } @@ -503,10 +503,10 @@ file_or_fd(struct magic_set *ms, const char *inname, int fd) } else { /* Windows refuses to read from a big console buffer. */ size_t howmany = -#if defined(WIN32) +#if defined(WIN32) && HOWMANY > 8 * 1024 _isatty(fd) ? 8 * 1024 : #endif - ms->bytes_max; + HOWMANY; if ((nbytes = read(fd, (char *)buf, howmany)) == -1) { if (inname == NULL && fd != STDIN_FILENO) file_error(ms, errno, "cannot read fd %d", fd); @@ -606,9 +606,6 @@ magic_setparam(struct magic_set *ms, int param, const void *val) case MAGIC_PARAM_REGEX_MAX: ms->elf_notes_max = (uint16_t)*(const size_t *)val; return 0; - case MAGIC_PARAM_BYTES_MAX: - ms->bytes_max = *(const size_t *)val; - return 0; default: errno = EINVAL; return -1; @@ -637,9 +634,6 @@ magic_getparam(struct magic_set *ms, int param, void *val) case MAGIC_PARAM_REGEX_MAX: *(size_t *)val = ms->regex_max; return 0; - case MAGIC_PARAM_BYTES_MAX: - *(size_t *)val = ms->bytes_max; - return 0; default: errno = EINVAL; return -1; |