summaryrefslogtreecommitdiffstats
path: root/contrib/file/src/magic.c
diff options
context:
space:
mode:
authorRenato Botelho <renato@netgate.com>2016-05-03 08:53:59 -0300
committerRenato Botelho <renato@netgate.com>2016-05-03 08:53:59 -0300
commit501575fb1206644a3ea8c2cd64a81084745445cc (patch)
treee07e5ad3f3ff6f6cf2841dd2d2eb0dcb0e54521a /contrib/file/src/magic.c
parent91f599cbc0d103dd112a2472b589573724b8d70a (diff)
parent04acf11bf47629b82fc88ce0e6d6dc642b1e641b (diff)
downloadFreeBSD-src-501575fb1206644a3ea8c2cd64a81084745445cc.zip
FreeBSD-src-501575fb1206644a3ea8c2cd64a81084745445cc.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.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/contrib/file/src/magic.c b/contrib/file/src/magic.c
index 87ac1cb..315a944 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.95 2015/09/11 17:24:09 christos Exp $")
+FILE_RCSID("@(#)$File: magic.c,v 1.97 2016/03/31 17:51:12 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 (fd == STDIN_FILENO || name == NULL)
+ if (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(HOWMANY + SLOP))) == NULL)
+ if ((buf = CAST(unsigned char *, malloc(ms->bytes_max + 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 HOWMANY bytes
+ * try looking at the first ms->bytes_max bytes
*/
if (ispipe) {
ssize_t r = 0;
while ((r = sread(fd, (void *)&buf[nbytes],
- (size_t)(HOWMANY - nbytes), 1)) > 0) {
+ (size_t)(ms->bytes_max - 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) && HOWMANY > 8 * 1024
+#if defined(WIN32)
_isatty(fd) ? 8 * 1024 :
#endif
- HOWMANY;
+ ms->bytes_max;
if ((nbytes = read(fd, (char *)buf, howmany)) == -1) {
if (inname == NULL && fd != STDIN_FILENO)
file_error(ms, errno, "cannot read fd %d", fd);
@@ -606,6 +606,9 @@ 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;
@@ -634,6 +637,9 @@ 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;
OpenPOWER on IntegriCloud