diff options
author | 2016-05-01 08:48:39 +0000 | |
---|---|---|
committer | 2016-05-01 08:48:39 +0000 | |
commit | e0a3e3d12ccc6cfa060e031de9a6b7cb7cb53600 (patch) | |
tree | 80560d534eec4b617c6e743a505d576e9551b2d8 /usr.bin/file | |
parent | convert ldapd to use the libtls api, bringing in a copy of the evbuffer_tls (diff) | |
download | wireguard-openbsd-e0a3e3d12ccc6cfa060e031de9a6b7cb7cb53600.tar.xz wireguard-openbsd-e0a3e3d12ccc6cfa060e031de9a6b7cb7cb53600.zip |
Add support for 'clear' test, and fix 'default' to expand the result
string if any (used by, for example, rtf).
Diffstat (limited to 'usr.bin/file')
-rw-r--r-- | usr.bin/file/magic-load.c | 15 | ||||
-rw-r--r-- | usr.bin/file/magic-test.c | 19 | ||||
-rw-r--r-- | usr.bin/file/magic.h | 3 |
3 files changed, 32 insertions, 5 deletions
diff --git a/usr.bin/file/magic-load.c b/usr.bin/file/magic-load.c index 4a62f10226f..00640cdf0b1 100644 --- a/usr.bin/file/magic-load.c +++ b/usr.bin/file/magic-load.c @@ -1,4 +1,4 @@ -/* $OpenBSD: magic-load.c,v 1.19 2015/11/15 22:11:18 tobias Exp $ */ +/* $OpenBSD: magic-load.c,v 1.20 2016/05/01 08:48:39 nicm Exp $ */ /* * Copyright (c) 2015 Nicholas Marriott <nicm@openbsd.org> @@ -191,7 +191,6 @@ magic_set_result(struct magic_line *ml, const char *s) else { switch (ml->type) { case MAGIC_TYPE_NONE: - case MAGIC_TYPE_DEFAULT: case MAGIC_TYPE_BESTRING16: case MAGIC_TYPE_LESTRING16: return (0); /* don't use result */ @@ -260,6 +259,8 @@ magic_set_result(struct magic_line *ml, const char *s) case MAGIC_TYPE_PSTRING: case MAGIC_TYPE_REGEX: case MAGIC_TYPE_SEARCH: + case MAGIC_TYPE_DEFAULT: + case MAGIC_TYPE_CLEAR: re = &ml->root->format_string; break; } @@ -295,6 +296,8 @@ magic_get_strength(struct magic_line *ml) case MAGIC_TYPE_NONE: case MAGIC_TYPE_DEFAULT: return (0); + case MAGIC_TYPE_CLEAR: + break; case MAGIC_TYPE_BYTE: case MAGIC_TYPE_UBYTE: n += 1 * MAGIC_STRENGTH_MULTIPLIER; @@ -794,6 +797,8 @@ magic_parse_type(struct magic_line *ml, char **line) ml->type = MAGIC_TYPE_MELDATE; else if (strcmp(s, "default") == 0 || strcmp(s, "udefault") == 0) ml->type = MAGIC_TYPE_DEFAULT; + else if (strcmp(s, "clear") == 0 || strcmp(s, "uclear") == 0) + ml->type = MAGIC_TYPE_CLEAR; else { magic_warn(ml, "unknown type: %s", s); goto fail; @@ -836,6 +841,12 @@ magic_parse_value(struct magic_line *ml, char **line) return (0); } + if (ml->type == MAGIC_TYPE_DEFAULT || ml->type == MAGIC_TYPE_CLEAR) { + magic_warn(ml, "test specified for default or clear"); + ml->test_operator = 'x'; + return (0); + } + if (**line == '!') { ml->test_not = 1; (*line)++; diff --git a/usr.bin/file/magic-test.c b/usr.bin/file/magic-test.c index c2dffd7b0cc..41474ef7dd8 100644 --- a/usr.bin/file/magic-test.c +++ b/usr.bin/file/magic-test.c @@ -1,4 +1,4 @@ -/* $OpenBSD: magic-test.c,v 1.19 2016/04/30 22:03:30 nicm Exp $ */ +/* $OpenBSD: magic-test.c,v 1.20 2016/05/01 08:48:39 nicm Exp $ */ /* * Copyright (c) 2015 Nicholas Marriott <nicm@openbsd.org> @@ -1053,9 +1053,20 @@ magic_test_type_search(struct magic_line *ml, struct magic_state *ms) static int magic_test_type_default(__unused struct magic_line *ml, struct magic_state *ms) { + if (!ms->matched && ml->result != NULL) + magic_add_result(ms, ml, "%s", ""); return (!ms->matched); } +static int +magic_test_type_clear(__unused struct magic_line *ml, + __unused struct magic_state *ms) +{ + if (ml->result != NULL) + magic_add_result(ms, ml, "%s", ""); + return (1); +} + static int (*magic_test_functions[])(struct magic_line *, struct magic_state *) = { magic_test_type_none, @@ -1119,6 +1130,7 @@ static int (*magic_test_functions[])(struct magic_line *, magic_test_type_regex, magic_test_type_search, magic_test_type_default, + magic_test_type_clear, }; static int @@ -1225,7 +1237,10 @@ magic_test_line(struct magic_line *ml, struct magic_state *ms) magic_test_line(child, ms); } - ms->matched = 1; + if (ml->type == MAGIC_TYPE_CLEAR) + ms->matched = 0; + else + ms->matched = 1; return (ml->result != NULL); } diff --git a/usr.bin/file/magic.h b/usr.bin/file/magic.h index 47c25598303..d2258c5db3d 100644 --- a/usr.bin/file/magic.h +++ b/usr.bin/file/magic.h @@ -1,4 +1,4 @@ -/* $OpenBSD: magic.h,v 1.12 2016/04/30 21:42:11 nicm Exp $ */ +/* $OpenBSD: magic.h,v 1.13 2016/05/01 08:48:39 nicm Exp $ */ /* * Copyright (c) 2015 Nicholas Marriott <nicm@openbsd.org> @@ -95,6 +95,7 @@ enum magic_type { MAGIC_TYPE_REGEX, MAGIC_TYPE_SEARCH, MAGIC_TYPE_DEFAULT, + MAGIC_TYPE_CLEAR, }; TAILQ_HEAD(magic_lines, magic_line); |