Ticket #3694: 3694-0003-Hex-patterns-fix-trailing-whitespace-problem.patch

File 3694-0003-Hex-patterns-fix-trailing-whitespace-problem.patch, 1.5 KB (added by mooffie, 7 years ago)
  • lib/search/hex.c

    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 
    8585        int ptr; 
    8686 
    8787        /* cppcheck-suppress invalidscanf */ 
    88         if (sscanf (tmp_str + loop, "%x%n", &val, &ptr)) 
     88        if (sscanf (tmp_str + loop, "%x%n", &val, &ptr) == 1) 
    8989        { 
    9090            if (val > 255) 
    9191                error = MC_SEARCH_HEX_E_NUM_OUT_OF_RANGE; 
  • tests/lib/search/hex_translate_to_regex.c

    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 
    5656        MC_SEARCH_HEX_E_OK 
    5757    }, 
    5858    { 
    59         /* Extra whitespace (but not trailing one) */ 
    60         "  12  34", 
     59        /* Extra whitespace */ 
     60        "  12  34  ", 
    6161        "\\x12\\x34", 
    6262        MC_SEARCH_HEX_E_OK 
    6363    },