Ticket #2028: 2028-in-hexC-missing-retchecks-and-g_free.patch

File 2028-in-hexC-missing-retchecks-and-g_free.patch, 1.7 KB (added by vit_r, 12 years ago)
  • lib/search/hex.c

    From c70b8c27dc47986f0bf42a19448cbd738a50fb9c Mon Sep 17 00:00:00 2001
    From: Vit Rosin <vit_r@list.ru>
    Date: Tue, 16 Feb 2010 15:18:39 +0000
    Subject: [PATCH]  lib/search/hex.c in mc_search__hex_translate_to_regex ():
                        missing checks of g_str...() return
                        and missing g_free (tmp_str);
    
    ---
     lib/search/hex.c |   20 ++++++++++++++++++--
     1 files changed, 18 insertions(+), 2 deletions(-)
    
    diff --git a/lib/search/hex.c b/lib/search/hex.c
    index 2ecdafb..8dd3bb5 100644
    a b  
    5151static GString * 
    5252mc_search__hex_translate_to_regex (gchar * str, gsize * len) 
    5353{ 
    54     GString *buff = g_string_new (""); 
    55     gchar *tmp_str = g_strndup (str, *len); 
     54    GString *buff; 
     55    gchar *tmp_str; 
    5656    gchar *tmp_str2; 
    5757    gsize loop = 0; 
    5858    int val, ptr; 
    5959 
     60    buff = g_string_new (""); 
     61    if (buff == NULL) 
     62        return NULL; 
     63 
     64    tmp_str = g_strndup (str, *len); 
     65    if (tmp_str == NULL) { 
     66        g_free (buff); 
     67        return NULL;     
     68    } 
     69 
    6070    g_strchug (tmp_str);        /* trim leadind whitespaces */ 
    6171 
    6272    while (loop < *len) { 
    mc_search__hex_translate_to_regex (gchar * str, gsize * len) 
    6676                continue; 
    6777            } 
    6878            tmp_str2 = g_strdup_printf ("\\x%02X", (unsigned char) val); 
     79            if (tmp_str2 == NULL) { 
     80                g_free (buff); 
     81                g_free (tmp_str); 
     82                return NULL;         
     83            } 
    6984            g_string_append (buff, tmp_str2); 
    7085            g_free (tmp_str2); 
    7186            loop += ptr; 
    mc_search__hex_translate_to_regex (gchar * str, gsize * len) 
    88103        loop++; 
    89104    } 
    90105    *len = buff->len; 
     106    g_free (tmp_str); 
    91107    return buff; 
    92108} 
    93109