diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2015-08-11 22:23:52 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2015-08-11 22:23:52 +0000 |
commit | ed01e8060875d13c7bbdb8e5978a050067cab604 (patch) | |
tree | ec2b624a8064855c481a482f0ed0e1a4803c9c2d /usr.bin/file/magic-load.c | |
parent | 14677e68b840f42def6d55a1c04ba11cc9ef88ec (diff) |
An invalid line can't just be thrown away because if it has any children
they will end up with the wrong parent. Instead, leave it in the tree
but force its type to NONE so it never matches.
Diffstat (limited to 'usr.bin/file/magic-load.c')
-rw-r--r-- | usr.bin/file/magic-load.c | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/usr.bin/file/magic-load.c b/usr.bin/file/magic-load.c index 0a5ae8d445a..7dcf9d73cbd 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.12 2015/08/11 22:18:43 nicm Exp $ */ +/* $OpenBSD: magic-load.c,v 1.13 2015/08/11 22:23:51 nicm Exp $ */ /* * Copyright (c) 2015 Nicholas Marriott <nicm@openbsd.org> @@ -284,6 +284,9 @@ magic_get_strength(struct magic_line *ml) int n; size_t size; + if (ml->type == MAGIC_TYPE_NONE) + return (0); + if (ml->test_not || ml->test_operator == 'x') return (1); @@ -884,17 +887,6 @@ fail: return (-1); } -static void -magic_free_line(struct magic_line *ml) -{ - free((void *)ml->type_string); - - free((void *)ml->mimetype); - free((void *)ml->result); - - free(ml); -} - int magic_compare(struct magic_line *ml1, struct magic_line *ml2) { @@ -1005,6 +997,11 @@ magic_load(FILE *f, const char *path, int warnings) TAILQ_INIT(&ml->children); ml->text = 1; + /* + * At this point n is the level we want, level is the current + * level. parent0 is the last line at the same level and parent + * is the last line at the previous level. + */ if (n == level + 1) { parent = parent0; } else if (n < level) { @@ -1022,7 +1019,11 @@ magic_load(FILE *f, const char *path, int warnings) magic_parse_type(ml, &line) != 0 || magic_parse_value(ml, &line) != 0 || magic_set_result(ml, line) != 0) { - magic_free_line(ml); + /* + * An invalid line still needs to appear in the tree in + * case it has any children. + */ + ml->type = MAGIC_TYPE_NONE; ml = NULL; continue; } |