summaryrefslogtreecommitdiff
path: root/usr.bin/file
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2015-08-11 22:18:44 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2015-08-11 22:18:44 +0000
commit14677e68b840f42def6d55a1c04ba11cc9ef88ec (patch)
tree05c772d25d288d24b4d788daa94bec9ac56322ab /usr.bin/file
parent6908b43e4b06bd96e096287fe15f40402eb7d83f (diff)
Extend accepted operators to +-&/%* for integer tests.
Diffstat (limited to 'usr.bin/file')
-rw-r--r--usr.bin/file/magic-load.c4
-rw-r--r--usr.bin/file/magic-test.c82
2 files changed, 83 insertions, 3 deletions
diff --git a/usr.bin/file/magic-load.c b/usr.bin/file/magic-load.c
index 7a30563a033..0a5ae8d445a 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.11 2015/08/11 22:12:48 nicm Exp $ */
+/* $OpenBSD: magic-load.c,v 1.12 2015/08/11 22:18:43 nicm Exp $ */
/*
* Copyright (c) 2015 Nicholas Marriott <nicm@openbsd.org>
@@ -628,7 +628,7 @@ magic_parse_type(struct magic_line *ml, char **line)
goto done;
}
- cp = &s[strcspn(s, "-&")];
+ cp = &s[strcspn(s, "+-&/%*")];
if (*cp != '\0') {
ml->type_operator = *cp;
endptr = magic_strtoull(cp + 1, &ml->type_operand);
diff --git a/usr.bin/file/magic-test.c b/usr.bin/file/magic-test.c
index bd9b6031269..941e8ed2d54 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.7 2015/08/11 22:12:48 nicm Exp $ */
+/* $OpenBSD: magic-test.c,v 1.8 2015/08/11 22:18:43 nicm Exp $ */
/*
* Copyright (c) 2015 Nicholas Marriott <nicm@openbsd.org>
@@ -235,6 +235,16 @@ magic_test_type_byte(struct magic_line *ml, struct magic_state *ms)
if (ml->type_operator == '&')
value &= (int8_t)ml->type_operand;
+ else if (ml->type_operator == '-')
+ value -= (int8_t)ml->type_operand;
+ else if (ml->type_operator == '+')
+ value += (int8_t)ml->type_operand;
+ else if (ml->type_operator == '/')
+ value /= (int8_t)ml->type_operand;
+ else if (ml->type_operator == '%')
+ value %= (int8_t)ml->type_operand;
+ else if (ml->type_operator == '*')
+ value *= (int8_t)ml->type_operand;
else if (ml->type_operator != ' ')
return (-1);
@@ -261,6 +271,16 @@ magic_test_type_short(struct magic_line *ml, struct magic_state *ms)
if (ml->type_operator == '&')
value &= (int16_t)ml->type_operand;
+ else if (ml->type_operator == '-')
+ value -= (int16_t)ml->type_operand;
+ else if (ml->type_operator == '+')
+ value += (int16_t)ml->type_operand;
+ else if (ml->type_operator == '/')
+ value /= (int16_t)ml->type_operand;
+ else if (ml->type_operator == '%')
+ value %= (int16_t)ml->type_operand;
+ else if (ml->type_operator == '*')
+ value *= (int16_t)ml->type_operand;
else if (ml->type_operator != ' ')
return (-1);
@@ -287,6 +307,16 @@ magic_test_type_long(struct magic_line *ml, struct magic_state *ms)
if (ml->type_operator == '&')
value &= (int32_t)ml->type_operand;
+ else if (ml->type_operator == '-')
+ value -= (int32_t)ml->type_operand;
+ else if (ml->type_operator == '+')
+ value += (int32_t)ml->type_operand;
+ else if (ml->type_operator == '/')
+ value /= (int32_t)ml->type_operand;
+ else if (ml->type_operator == '%')
+ value %= (int32_t)ml->type_operand;
+ else if (ml->type_operator == '*')
+ value *= (int32_t)ml->type_operand;
else if (ml->type_operator != ' ')
return (-1);
@@ -313,6 +343,16 @@ magic_test_type_quad(struct magic_line *ml, struct magic_state *ms)
if (ml->type_operator == '&')
value &= (int64_t)ml->type_operand;
+ else if (ml->type_operator == '-')
+ value -= (int64_t)ml->type_operand;
+ else if (ml->type_operator == '+')
+ value += (int64_t)ml->type_operand;
+ else if (ml->type_operator == '/')
+ value /= (int64_t)ml->type_operand;
+ else if (ml->type_operator == '%')
+ value %= (int64_t)ml->type_operand;
+ else if (ml->type_operator == '*')
+ value *= (int64_t)ml->type_operand;
else if (ml->type_operator != ' ')
return (-1);
@@ -335,6 +375,16 @@ magic_test_type_ubyte(struct magic_line *ml, struct magic_state *ms)
if (ml->type_operator == '&')
value &= (uint8_t)ml->type_operand;
+ else if (ml->type_operator == '-')
+ value -= (uint8_t)ml->type_operand;
+ else if (ml->type_operator == '+')
+ value += (uint8_t)ml->type_operand;
+ else if (ml->type_operator == '/')
+ value /= (uint8_t)ml->type_operand;
+ else if (ml->type_operator == '%')
+ value %= (uint8_t)ml->type_operand;
+ else if (ml->type_operator == '*')
+ value *= (uint8_t)ml->type_operand;
else if (ml->type_operator != ' ')
return (-1);
@@ -361,6 +411,16 @@ magic_test_type_ushort(struct magic_line *ml, struct magic_state *ms)
if (ml->type_operator == '&')
value &= (uint16_t)ml->type_operand;
+ else if (ml->type_operator == '-')
+ value -= (uint16_t)ml->type_operand;
+ else if (ml->type_operator == '+')
+ value += (uint16_t)ml->type_operand;
+ else if (ml->type_operator == '/')
+ value /= (uint16_t)ml->type_operand;
+ else if (ml->type_operator == '%')
+ value %= (uint16_t)ml->type_operand;
+ else if (ml->type_operator == '*')
+ value *= (uint16_t)ml->type_operand;
else if (ml->type_operator != ' ')
return (-1);
@@ -387,6 +447,16 @@ magic_test_type_ulong(struct magic_line *ml, struct magic_state *ms)
if (ml->type_operator == '&')
value &= (uint32_t)ml->type_operand;
+ else if (ml->type_operator == '-')
+ value -= (uint32_t)ml->type_operand;
+ else if (ml->type_operator == '+')
+ value += (uint32_t)ml->type_operand;
+ else if (ml->type_operator == '/')
+ value /= (uint32_t)ml->type_operand;
+ else if (ml->type_operator == '%')
+ value %= (uint32_t)ml->type_operand;
+ else if (ml->type_operator == '*')
+ value *= (uint32_t)ml->type_operand;
else if (ml->type_operator != ' ')
return (-1);
@@ -413,6 +483,16 @@ magic_test_type_uquad(struct magic_line *ml, struct magic_state *ms)
if (ml->type_operator == '&')
value &= (uint64_t)ml->type_operand;
+ else if (ml->type_operator == '-')
+ value -= (uint64_t)ml->type_operand;
+ else if (ml->type_operator == '+')
+ value += (uint64_t)ml->type_operand;
+ else if (ml->type_operator == '/')
+ value /= (uint64_t)ml->type_operand;
+ else if (ml->type_operator == '%')
+ value %= (uint64_t)ml->type_operand;
+ else if (ml->type_operator == '*')
+ value *= (uint64_t)ml->type_operand;
else if (ml->type_operator != ' ')
return (-1);