From 69db8f5e9f965596de1d43415a869ed0420ce5f8 Mon Sep 17 00:00:00 2001
From: Mooffie <mooffie@gmail.com>
Date: Sun, 25 Sep 2016 17:24:44 +0300
Subject: [PATCH 3/8] Hex patterns: fix trailing whitespace problem.
sscanf() returns EOF when it reaches the end of the string. Our code
erroneously interprets this as if a number was read. The fix: we test for an
explicit '1'.
---
lib/search/hex.c | 2 +-
tests/lib/search/hex_translate_to_regex.c | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/lib/search/hex.c b/lib/search/hex.c
index a56d173..524a322 100644
a
|
b
|
mc_search__hex_translate_to_regex (const GString * astr, mc_search_hex_parse_err |
85 | 85 | int ptr; |
86 | 86 | |
87 | 87 | /* cppcheck-suppress invalidscanf */ |
88 | | if (sscanf (tmp_str + loop, "%x%n", &val, &ptr)) |
| 88 | if (sscanf (tmp_str + loop, "%x%n", &val, &ptr) == 1) |
89 | 89 | { |
90 | 90 | if (val > 255) |
91 | 91 | error = MC_SEARCH_HEX_E_NUM_OUT_OF_RANGE; |
diff --git a/tests/lib/search/hex_translate_to_regex.c b/tests/lib/search/hex_translate_to_regex.c
index cd53486..c72dff9 100644
a
|
b
|
static const struct test_hex_translate_to_regex_ds |
56 | 56 | MC_SEARCH_HEX_E_OK |
57 | 57 | }, |
58 | 58 | { |
59 | | /* Extra whitespace (but not trailing one) */ |
60 | | " 12 34", |
| 59 | /* Extra whitespace */ |
| 60 | " 12 34 ", |
61 | 61 | "\\x12\\x34", |
62 | 62 | MC_SEARCH_HEX_E_OK |
63 | 63 | }, |