From 390bbf85b062d7afdb634bb11bdb046cee6c6954 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Sat, 30 Apr 2016 21:42:12 +0000 Subject: Fix the default type to work properly, that is to only match if no previous test at the same level has matched. --- usr.bin/file/magic-test.c | 7 +++++-- usr.bin/file/magic.h | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/usr.bin/file/magic-test.c b/usr.bin/file/magic-test.c index 1101de18f1e..9d4e11c7567 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.17 2016/04/30 21:10:28 nicm Exp $ */ +/* $OpenBSD: magic-test.c,v 1.18 2016/04/30 21:42:11 nicm Exp $ */ /* * Copyright (c) 2015 Nicholas Marriott @@ -1054,7 +1054,7 @@ static int magic_test_type_default(__unused struct magic_line *ml, __unused struct magic_state *ms) { - return (1); + return (!ms->matched); } static int (*magic_test_functions[])(struct magic_line *, @@ -1219,11 +1219,14 @@ magic_test_line(struct magic_line *ml, struct magic_state *ms) ml->type_string, ml->test_operator, offset, ms->offset, ml->result == NULL ? "" : ml->result); + ms->matched = 0; offset = ms->offset; TAILQ_FOREACH(child, &ml->children, entry) { ms->offset = offset; magic_test_line(child, ms); } + + ms->matched = 1; return (ml->result != NULL); } diff --git a/usr.bin/file/magic.h b/usr.bin/file/magic.h index e1c9fc1a8fd..47c25598303 100644 --- a/usr.bin/file/magic.h +++ b/usr.bin/file/magic.h @@ -1,4 +1,4 @@ -/* $OpenBSD: magic.h,v 1.11 2015/10/05 20:05:52 nicm Exp $ */ +/* $OpenBSD: magic.h,v 1.12 2016/04/30 21:42:11 nicm Exp $ */ /* * Copyright (c) 2015 Nicholas Marriott @@ -164,6 +164,7 @@ struct magic_state { const char *base; size_t size; size_t offset; + int matched; }; #define MAGIC_TEST_TEXT 0x1 -- cgit v1.2.3