Get rid of TestBigEndian and AC_C_BIGENDIAN.
[metze/wireshark/wip.git] / epan / oids.c
index 169319bbac3098747f5e22980d5de6671b05330c..28ea769d8352c2852e84d4d6446e43f3c7fa46a8 100644 (file)
@@ -3,25 +3,11 @@
  *
  * (c) 2007, Luis E. Garcia Ontanon <luis@ontanon.org>
  *
- * $Id$
- *
  * Wireshark - Network traffic analyzer
  * By Gerald Combs <gerald@wireshark.org>
  * Copyright 1998 Gerald Combs
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: GPL-2.0-or-later
  */
 
 #include "config.h"
 #include <glib.h>
 #include <stdio.h>
 #include <string.h>
-#include <ctype.h>
 
-#include <wsutil/report_err.h>
+#include <wsutil/report_message.h>
 
-#include "emem.h"
 #include "wmem/wmem.h"
 #include "uat.h"
 #include "prefs.h"
@@ -41,6 +25,7 @@
 #include "packet.h"
 #include "wsutil/filesystem.h"
 #include "dissectors/packet-ber.h"
+#include <wsutil/ws_printf.h> /* ws_debug_printf */
 
 #ifdef HAVE_LIBSMI
 #include <smi.h>
@@ -50,7 +35,7 @@ static gboolean load_smi_modules = FALSE;
 static gboolean suppress_smi_errors = FALSE;
 #endif
 
-#define D(level,args) do if (debuglevel >= level) { printf args; printf("\n"); fflush(stdout); } while(0)
+#define D(level,args) do if (debuglevel >= level) { ws_debug_printf args; ws_debug_printf("\n"); fflush(stdout); } while(0)
 
 #include "oids.h"
 
@@ -68,6 +53,7 @@ static int debuglevel = 0;
  * the BER encoding may take 5 octets to encode.
  */
 
+#ifdef HAVE_LIBSMI
 static const oid_value_type_t integer_type =    { FT_INT32,  BASE_DEC,  BER_CLASS_UNI, BER_UNI_TAG_INTEGER,     1,   4, OID_KEY_TYPE_INTEGER, 1};
 static const oid_value_type_t bytes_type =      { FT_BYTES,  BASE_NONE, BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, 0,  -1, OID_KEY_TYPE_BYTES,   0};
 static const oid_value_type_t oid_type =        { FT_OID,    BASE_NONE, BER_CLASS_UNI, BER_UNI_TAG_OID,         1,  -1, OID_KEY_TYPE_OID,     0};
@@ -86,6 +72,8 @@ static const oid_value_type_t double_type =     { FT_DOUBLE, BASE_DEC,  BER_CLAS
 static const oid_value_type_t ether_type =      { FT_ETHER,  BASE_NONE, BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, 6,   6, OID_KEY_TYPE_ETHER,   6};
 static const oid_value_type_t string_type =     { FT_STRING, BASE_NONE, BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, 0,  -1, OID_KEY_TYPE_STRING,  0};
 static const oid_value_type_t date_and_time_type = { FT_STRING,  BASE_NONE, BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, 8,  11, OID_KEY_TYPE_DATE_AND_TIME,   0};
+#endif /* HAVE_LIBSMI */
+
 static const oid_value_type_t unknown_type =    { FT_BYTES,  BASE_NONE, BER_CLASS_ANY, BER_TAG_ANY,             0,  -1, OID_KEY_TYPE_WRONG,   0};
 
 static oid_info_t oid_root = { 0, NULL, OID_KIND_UNKNOWN, NULL, &unknown_type, -2, NULL, NULL, NULL};
@@ -109,7 +97,7 @@ static void prepopulate_oids(void) {
        }
 }
 
-       
+
 
 static oid_info_t* add_oid(const char* name, oid_kind_t kind, const oid_value_type_t* type, oid_key_t* key, guint oid_len, guint32 *subids) {
        guint i = 0;
@@ -171,8 +159,10 @@ static oid_info_t* add_oid(const char* name, oid_kind_t kind, const oid_value_ty
 void oid_add(const char* name, guint oid_len, guint32 *subids) {
        g_assert(subids && *subids <= 2);
        if (oid_len) {
-               D(3,("\tOid (from subids): %s %s ",name?name:"NULL", oid_subid2string(subids,oid_len)));
+               gchar* sub = oid_subid2string(NULL, subids,oid_len);
+               D(3,("\tOid (from subids): %s %s ",name?name:"NULL", sub));
                add_oid(name,OID_KIND_UNKNOWN,NULL,NULL,oid_len,subids);
+               wmem_free(NULL, sub);
        } else {
                D(1,("Failed to add Oid: %s (from subids)",name?name:"NULL"));
        }
@@ -183,8 +173,10 @@ void oid_add_from_string(const char* name, const gchar *oid_str) {
        guint oid_len = oid_string2subid(NULL, oid_str, &subids);
 
        if (oid_len) {
-               D(3,("\tOid (from string): %s %s ",name?name:"NULL", oid_subid2string(subids,oid_len)));
+               gchar* sub = oid_subid2string(NULL, subids,oid_len);
+               D(3,("\tOid (from string): %s %s ",name?name:"NULL", sub));
                add_oid(name,OID_KIND_UNKNOWN,NULL,NULL,oid_len,subids);
+               wmem_free(NULL, sub);
        } else {
                D(1,("Failed to add Oid: %s %s ",name?name:"NULL", oid_str?oid_str:NULL));
        }
@@ -192,15 +184,20 @@ void oid_add_from_string(const char* name, const gchar *oid_str) {
 }
 
 extern void oid_add_from_encoded(const char* name, const guint8 *oid, gint oid_len) {
-       guint32* subids;
-       guint subids_len = oid_encoded2subid(oid, oid_len, &subids);
+       guint32* subids = NULL;
+       guint subids_len = oid_encoded2subid(NULL, oid, oid_len, &subids);
 
        if (subids_len) {
-               D(3,("\tOid (from encoded): %s %s ",name, oid_subid2string(subids,subids_len)));
+               gchar* sub = oid_subid2string(NULL, subids,subids_len);
+               D(3,("\tOid (from encoded): %s %s ",name, sub));
                add_oid(name,OID_KIND_UNKNOWN,NULL,NULL,subids_len,subids);
+               wmem_free(NULL, sub);
        } else {
-               D(1,("Failed to add Oid: %s [%d]%s ",name?name:"NULL", oid_len,bytestring_to_ep_str(oid, oid_len, ':')));
+               gchar* bytestr = bytestring_to_str(NULL, oid, oid_len, ':');
+               D(1,("Failed to add Oid: %s [%d]%s ",name?name:"NULL", oid_len, bytestr));
+               wmem_free(NULL, bytestr);
        }
+       wmem_free(NULL, subids);
 }
 
 #ifdef HAVE_LIBSMI
@@ -273,7 +270,7 @@ static char* alnumerize(const char* name) {
        char c;
 
        for (;(c = *r); r++) {
-               if (isalnum(c) || c == '_' || c == '-' || c == '.') {
+               if (g_ascii_isalnum(c) || c == '_' || c == '-' || c == '.') {
                        *(w++) = c;
                } else if (c == ':' && r[1] == ':') {
                        *(w++) = '.';
@@ -429,7 +426,7 @@ static inline oid_kind_t smikind(SmiNode* sN, oid_key_t** key_p) {
 
                                oid1 = smiRenderOID(sN->oidlen, sN->oid, SMI_RENDER_QUALIFIED);
                                oid2 = smiRenderOID(elNode->oidlen, elNode->oid, SMI_RENDER_NAME);
-                               k->name = g_strdup_printf("%s.%s", oid1, oid2);
+                               k->name = g_strconcat(oid1, ".", oid2, NULL);
                                smi_free (oid1);
                                smi_free (oid2);
 
@@ -561,9 +558,9 @@ static void register_mibs(void) {
                } else {
                        char* mod_name =  smiLoadModule(smi_modules[i].name);
                        if (mod_name)
-                               D(2,("Loaded: '%s'[%d] as %s",smi_modules[i].name,i,mod_name ));
+                               D(2,("Loaded: '%s'[%u] as %s",smi_modules[i].name,i,mod_name ));
                        else
-                               D(1,("Failed to load: '%s'[%d]",smi_modules[i].name,i));
+                               D(1,("Failed to load: '%s'[%u]",smi_modules[i].name,i));
                }
        }
 
@@ -609,6 +606,7 @@ static void register_mibs(void) {
                        const oid_value_type_t* typedata =  get_typedata(smiType);
                        oid_key_t* key;
                        oid_kind_t kind = smikind(smiNode,&key);
+                       char *sub;
                        char *oid = smiRenderOID(smiNode->oidlen, smiNode->oid, SMI_RENDER_QUALIFIED);
                        oid_info_t* oid_data = add_oid(oid,
                                                       kind,
@@ -618,33 +616,36 @@ static void register_mibs(void) {
                                                       smiNode->oid);
                        smi_free (oid);
 
+                       sub = oid_subid2string(NULL, smiNode->oid, smiNode->oidlen);
                        D(4,("\t\tNode: kind=%d oid=%s name=%s ",
-                                oid_data->kind, oid_subid2string(smiNode->oid, smiNode->oidlen), oid_data->name ));
+                                oid_data->kind, sub, oid_data->name));
+                       wmem_free(NULL, sub);
 
                        if ( typedata && oid_data->value_hfid == -2 ) {
                                SmiNamedNumber* smiEnum;
                                hf_register_info hf;
+                               char *name;
+                               char *blurb;
 
-                hf.p_id                     = &(oid_data->value_hfid);
-                hf.hfinfo.name              = oid_data->name;
-                hf.hfinfo.abbrev            = alnumerize(oid_data->name);
-                hf.hfinfo.type              = typedata->ft_type;
-                hf.hfinfo.display           = typedata->display;
-                hf.hfinfo.strings           = NULL;
-                hf.hfinfo.bitmask           = 0;
-                hf.hfinfo.blurb             = smiRenderOID(smiNode->oidlen, smiNode->oid, SMI_RENDER_ALL);
-                hf.hfinfo.id                = -1;
-                hf.hfinfo.parent            = 0;
-                hf.hfinfo.ref_type          = HF_REF_TYPE_NONE;
-                hf.hfinfo.same_name_prev_id = -1;
-                hf.hfinfo.same_name_next    = NULL;
-
+                               name = g_strdup(oid_data->name);
+                               blurb = smiRenderOID(smiNode->oidlen, smiNode->oid, SMI_RENDER_ALL);
                                /* Don't allow duplicate blurb/name */
-                               if (strcmp(hf.hfinfo.blurb, hf.hfinfo.name) == 0) {
-                                       smi_free((void *) hf.hfinfo.blurb);
-                                       hf.hfinfo.blurb = NULL;
+                               if (strcmp(blurb, name) == 0) {
+                                       smi_free(blurb);
+                                       blurb = NULL;
                                }
 
+                               hf.p_id                     = &(oid_data->value_hfid);
+                               hf.hfinfo.name              = name;
+                               hf.hfinfo.abbrev            = alnumerize(oid_data->name);
+                               hf.hfinfo.type              = typedata->ft_type;
+                               hf.hfinfo.display           = typedata->display;
+                               hf.hfinfo.strings           = NULL;
+                               hf.hfinfo.bitmask           = 0;
+                               hf.hfinfo.blurb             = blurb;
+                               /* HFILL */
+                               HFILL_INIT(hf);
+
                                oid_data->value_hfid = -1;
 
                                if ( IS_ENUMABLE(hf.hfinfo.type) && (smiEnum = smiGetFirstNamedNumber(smiType))) {
@@ -652,9 +653,9 @@ static void register_mibs(void) {
 
                                        for(;smiEnum; smiEnum = smiGetNextNamedNumber(smiEnum)) {
                                                if (smiEnum->name) {
-                            value_string val;
-                            val.value  = (guint32)smiEnum->value.value.integer32;
-                            val.strptr = g_strdup(smiEnum->name);
+                                                       value_string val;
+                                                       val.value  = (guint32)smiEnum->value.value.integer32;
+                                                       val.strptr = g_strdup(smiEnum->name);
                                                        g_array_append_val(vals,val);
                                                }
                                        }
@@ -688,8 +689,8 @@ static void register_mibs(void) {
                                        bits->data[n].hfid = -1;
                                        bits->data[n].offset = smiEnum->value.value.integer32 / 8;
 
-                                       hf2.hfinfo.name = g_strdup_printf("%s:%s",oid_data->name,smiEnum->name);
-                                       hf2.hfinfo.abbrev = g_strdup_printf("%s.%s",base,ext);
+                                       hf2.hfinfo.name = g_strconcat("%s:%s",oid_data->name, ":", smiEnum->name, NULL);
+                                       hf2.hfinfo.abbrev = g_strconcat(base, ".", ext, NULL);
 
                                        g_free(base);
                                        g_free(ext);
@@ -701,31 +702,25 @@ static void register_mibs(void) {
 
                        if ((key = oid_data->key)) {
                                for(; key; key = key->next) {
-                                       hf_register_info hf;
-
-                                       hf.p_id                     = &(key->hfid);
-                                       hf.hfinfo.name              = key->name;
-                                       hf.hfinfo.abbrev            = alnumerize(key->name);
-                                       hf.hfinfo.type              = key->ft_type;
-                                       hf.hfinfo.display           = key->display;
-                                       hf.hfinfo.strings           = NULL;
-                                       hf.hfinfo.bitmask           = 0;
-                                       hf.hfinfo.blurb             = NULL;
-                                       hf.hfinfo.id                = -1;
-                                       hf.hfinfo.parent            = 0;
-                                       hf.hfinfo.ref_type          = HF_REF_TYPE_NONE;
-                                       hf.hfinfo.same_name_prev_id = -1;
-                                       hf.hfinfo.same_name_next    = NULL;
-
-
-                                       D(5,("\t\t\tIndex: name=%s subids=%d key_type=%d",
+                                       D(5,("\t\t\tIndex: name=%s subids=%u key_type=%d",
                                                 key->name, key->num_subids, key->key_type ));
 
                                        if (key->hfid == -2) {
+                                               hf_register_info hf;
+
+                                               hf.p_id                     = &(key->hfid);
+                                               hf.hfinfo.name              = key->name;
+                                               hf.hfinfo.abbrev            = alnumerize(key->name);
+                                               hf.hfinfo.type              = key->ft_type;
+                                               hf.hfinfo.display           = key->display;
+                                               hf.hfinfo.strings           = NULL;
+                                               hf.hfinfo.bitmask           = 0;
+                                               hf.hfinfo.blurb             = NULL;
+                                               /* HFILL */
+                                               HFILL_INIT(hf);
+
                                                wmem_array_append_one(hfa,hf);
                                                key->hfid = -1;
-                                       } else {
-                                               g_free((void*)hf.hfinfo.abbrev);
                                        }
                                }
                        }
@@ -756,12 +751,16 @@ void oid_pref_init(module_t *nameres)
 
     prefs_register_bool_preference(nameres, "load_smi_modules",
                                   "Enable OID resolution",
-                                  "You must restart Wireshark for this change to take effect",
+                                  "Resolve Object IDs to object names from the MIB and PIB"
+                                  " modules defined below."
+                                  " You must restart Wireshark for this change to take effect",
                                   &load_smi_modules);
 
     prefs_register_bool_preference(nameres, "suppress_smi_errors",
                                   "Suppress SMI errors",
-                                  "Some errors can be ignored. If unsure, set to false.",
+                                  "While loading MIB or PIB modules errors may be detected,"
+                                  " which are reported. Some errors can be ignored."
+                                  " If unsure, set to false.",
                                   &suppress_smi_errors);
 
     smi_paths_uat = uat_new("SMI Paths",
@@ -783,13 +782,14 @@ void oid_pref_init(module_t *nameres)
                             NULL,
                             smi_mod_free_cb,
                             restart_needed_warning,
+                            NULL,
                             smi_paths_fields);
 
     prefs_register_uat_preference(nameres,
                                   "smi_paths",
                                   "SMI (MIB and PIB) paths",
-                                  "Search paths for SMI (MIB and PIB) modules. You must\n"
-                                  "restart Wireshark for these changes to take effect.",
+                                  "Search paths for SMI (MIB and PIB) modules. You must"
+                                  " restart Wireshark for these changes to take effect.",
                                   smi_paths_uat);
 
     smi_modules_uat = uat_new("SMI Modules",
@@ -811,13 +811,14 @@ void oid_pref_init(module_t *nameres)
                               NULL,
                               smi_mod_free_cb,
                               restart_needed_warning,
+                              NULL,
                               smi_fields);
 
     prefs_register_uat_preference(nameres,
                                   "smi_modules",
                                   "SMI (MIB and PIB) modules",
-                                  "List of enabled SMI (MIB and PIB) modules. You must\n"
-                                  "restart Wireshark for these changes to take effect.",
+                                  "List of SMI (MIB and PIB) modules to load. You must"
+                                  " restart Wireshark for these changes to take effect.",
                                   smi_modules_uat);
 
 #else
@@ -852,28 +853,31 @@ void oids_cleanup(void) {
 #endif
 }
 
-const char* oid_subid2string(guint32* subids, guint len) {
-    return rel_oid_subid2string(subids, len, TRUE);
+char* oid_subid2string(wmem_allocator_t *scope, guint32* subids, guint len) {
+       return rel_oid_subid2string(scope, subids, len, TRUE);
 }
-const char* rel_oid_subid2string(guint32* subids, guint len, gboolean is_absolute) {
-       char *s, *w;
+char* rel_oid_subid2string(wmem_allocator_t *scope, guint32* subids, guint len, gboolean is_absolute) {
+
+       wmem_strbuf_t *oid_str;
+       gsize oid_str_len;
 
        if(!subids || len == 0)
-               return "*** Empty OID ***";
+               return wmem_strdup(scope, "*** Empty OID ***");
 
-       s = (char *)ep_alloc0(((len)*11)+2);
-       w = s;
+       oid_str = wmem_strbuf_new(scope, "");
 
        if (!is_absolute)
-               *w++ = '.';
+               wmem_strbuf_append_c(oid_str, '.');
 
        do {
-               w += g_snprintf(w,12,"%u.",*subids++);
+               wmem_strbuf_append_printf(oid_str, "%u.",*subids++);
        } while(--len);
 
-       if (w!=s) *(w-1) = '\0'; else *(s) = '\0';
+       /* Remove trailing "." (which is guaranteed to be there) */
+       oid_str_len = wmem_strbuf_get_len(oid_str);
+       wmem_strbuf_truncate(oid_str, oid_str_len - 1);
 
-       return s;
+       return wmem_strbuf_finalize(oid_str);
 }
 
 static guint check_num_oid(const char* str) {
@@ -885,9 +889,9 @@ static guint check_num_oid(const char* str) {
        if (!r) return 0;
 
        do {
-               D(9,("\tcheck_num_oid: '%c' %d",*r,n));
+               D(9,("\tcheck_num_oid: '%c' %u",*r,n));
                switch(*r) {
-            case '.': case '\0':
+                       case '.': case '\0':
                                n++;
                                if (c == '.') return 0;
                                break;
@@ -933,6 +937,7 @@ guint oid_string2subid(wmem_allocator_t *scope, const char* str, guint32** subid
                        subid += *r - '0';
 
                        if( subids >= subids_overflow ||  subid > 0xffffffff) {
+                               wmem_free(scope, *subids_p);
                                *subids_p=NULL;
                                return 0;
                        }
@@ -950,10 +955,10 @@ guint oid_string2subid(wmem_allocator_t *scope, const char* str, guint32** subid
 }
 
 
-guint oid_encoded2subid(const guint8 *oid_bytes, gint oid_len, guint32** subids_p) {
-       return oid_encoded2subid_sub(oid_bytes, oid_len, subids_p, TRUE);
+guint oid_encoded2subid(wmem_allocator_t *scope, const guint8 *oid_bytes, gint oid_len, guint32** subids_p) {
+       return oid_encoded2subid_sub(scope, oid_bytes, oid_len, subids_p, TRUE);
 }
-guint oid_encoded2subid_sub(const guint8 *oid_bytes, gint oid_len, guint32** subids_p,
+guint oid_encoded2subid_sub(wmem_allocator_t *scope, const guint8 *oid_bytes, gint oid_len, guint32** subids_p,
                gboolean is_first) {
        gint i;
        guint n = is_first ? 1 : 0;
@@ -967,7 +972,7 @@ guint oid_encoded2subid_sub(const guint8 *oid_bytes, gint oid_len, guint32** sub
 
        for (i=0; i<oid_len; i++) { if (! (oid_bytes[i] & 0x80 )) n++; }
 
-       *subids_p = subids = (guint32 *)ep_alloc(sizeof(guint32)*n);
+       *subids_p = subids = (guint32 *)wmem_alloc(scope, sizeof(guint32)*n);
        subid_overflow = subids+n;
 
        /* If n is 0 or 1 (depending on how it was initialized) then we found
@@ -1005,7 +1010,10 @@ guint oid_encoded2subid_sub(const guint8 *oid_bytes, gint oid_len, guint32** sub
                }
 
                if( subids >= subid_overflow || subid > 0xffffffff) {
-                       *subids_p=NULL;
+                       /* scope may be NULL in which case we must free our
+                        * useless buffer before returning */
+                       wmem_free(scope, *subids_p);
+                       *subids_p = NULL;
                        return 0;
                }
 
@@ -1043,8 +1051,8 @@ done:
 }
 
 
-oid_info_t* oid_get_from_encoded(const guint8 *bytes, gint byteslen, guint32** subids_p, guint* matched_p, guint* left_p) {
-       guint subids_len = oid_encoded2subid(bytes, byteslen, subids_p);
+oid_info_t* oid_get_from_encoded(wmem_allocator_t *scope, const guint8 *bytes, gint byteslen, guint32** subids_p, guint* matched_p, guint* left_p) {
+       guint subids_len = oid_encoded2subid(scope, bytes, byteslen, subids_p);
        return oid_get(subids_len, *subids_p, matched_p, left_p);
 }
 
@@ -1053,22 +1061,28 @@ oid_info_t* oid_get_from_string(wmem_allocator_t *scope, const gchar *oid_str, g
        return oid_get(subids_len, *subids_p, matched, left);
 }
 
-const gchar *oid_resolved_from_encoded(const guint8 *oid, gint oid_len) {
-       guint32 *subid_oid;
-       guint subid_oid_length = oid_encoded2subid(oid, oid_len, &subid_oid);
+gchar *oid_resolved_from_encoded(wmem_allocator_t *scope, const guint8 *oid, gint oid_len) {
+       guint32 *subid_oid = NULL;
+       gchar * ret;
+       guint subid_oid_length = oid_encoded2subid(NULL, oid, oid_len, &subid_oid);
 
-       return oid_resolved(subid_oid_length, subid_oid);
+       ret = oid_resolved(scope, subid_oid_length, subid_oid);
+       wmem_free(NULL, subid_oid);
+       return ret;
 }
 
-const gchar *rel_oid_resolved_from_encoded(const guint8 *oid, gint oid_len) {
-       guint32 *subid_oid;
-       guint subid_oid_length = oid_encoded2subid_sub(oid, oid_len, &subid_oid, FALSE);
+gchar *rel_oid_resolved_from_encoded(wmem_allocator_t *scope, const guint8 *oid, gint oid_len) {
+       guint32 *subid_oid = NULL;
+       gchar* ret;
+       guint subid_oid_length = oid_encoded2subid_sub(NULL, oid, oid_len, &subid_oid, FALSE);
 
-       return rel_oid_subid2string(subid_oid, subid_oid_length, FALSE);
+       ret = rel_oid_subid2string(scope, subid_oid, subid_oid_length, FALSE);
+       wmem_free(NULL, subid_oid);
+       return ret;
 }
 
 
-guint oid_subid2encoded(guint subids_len, guint32* subids, guint8** bytes_p) {
+guint oid_subid2encoded(wmem_allocator_t *scope, guint subids_len, guint32* subids, guint8** bytes_p) {
        guint bytelen = 0;
        guint i;
        guint32 subid;
@@ -1092,9 +1106,9 @@ guint oid_subid2encoded(guint subids_len, guint32* subids, guint8** bytes_p) {
                } else {
                        bytelen += 5;
                }
-       } 
+       }
 
-       *bytes_p = b = (guint8 *)ep_alloc(bytelen);
+       *bytes_p = b = (guint8 *)wmem_alloc(scope, bytelen);
 
        for (subid=subids[0] * 40, i = 1; i<subids_len; i++, subid=0) {
                guint len;
@@ -1109,45 +1123,57 @@ guint oid_subid2encoded(guint subids_len, guint32* subids, guint8** bytes_p) {
                switch(len) {
                        default: *bytes_p=NULL; return 0;
                        case 5: *(b++) = ((subid & 0xF0000000) >> 28) | 0x80;
+                       /* FALL THROUGH */
                        case 4: *(b++) = ((subid & 0x0FE00000) >> 21) | 0x80;
+                       /* FALL THROUGH */
                        case 3: *(b++) = ((subid & 0x001FC000) >> 14) | 0x80;
+                       /* FALL THROUGH */
                        case 2: *(b++) = ((subid & 0x00003F80) >> 7)  | 0x80;
+                       /* FALL THROUGH */
                        case 1: *(b++) =   subid & 0x0000007F ; break;
                }
-       } 
+       }
 
        return bytelen;
 }
 
-const gchar* oid_encoded2string(const guint8* encoded, guint len) {
-       guint32* subids;
-       guint subids_len = oid_encoded2subid(encoded, len, &subids);
+gchar* oid_encoded2string(wmem_allocator_t *scope, const guint8* encoded, guint len) {
+       guint32* subids = NULL;
+       gchar* ret;
+       guint subids_len = oid_encoded2subid(NULL, encoded, len, &subids);
 
        if (subids_len) {
-               return oid_subid2string(subids,subids_len);
+               ret = oid_subid2string(scope, subids,subids_len);
        } else {
-               return "";
+               ret = wmem_strdup(scope, "");
        }
+
+       wmem_free(NULL, subids);
+       return ret;
 }
 
-const gchar* rel_oid_encoded2string(const guint8* encoded, guint len) {
-       guint32* subids;
-       guint subids_len = oid_encoded2subid_sub(encoded, len, &subids, FALSE);
+gchar* rel_oid_encoded2string(wmem_allocator_t *scope, const guint8* encoded, guint len) {
+       guint32* subids = NULL;
+       gchar* ret;
+       guint subids_len = oid_encoded2subid_sub(NULL, encoded, len, &subids, FALSE);
 
        if (subids_len) {
-               return rel_oid_subid2string(subids,subids_len, FALSE);
+               ret = rel_oid_subid2string(scope, subids,subids_len, FALSE);
        } else {
-               return "";
+               ret = wmem_strdup(scope, "");
        }
+
+       wmem_free(NULL, subids);
+       return ret;
 }
 
-guint oid_string2encoded(const char *oid_str, guint8 **bytes) {
+guint oid_string2encoded(wmem_allocator_t *scope, const char *oid_str, guint8 **bytes) {
        guint32* subids;
        guint32 subids_len;
        guint byteslen;
 
        if ( (subids_len = oid_string2subid(NULL, oid_str, &subids)) &&
-            (byteslen   = oid_subid2encoded(subids_len, subids, bytes)) ) {
+            (byteslen   = oid_subid2encoded(scope, subids_len, subids, bytes)) ) {
                wmem_free(NULL, subids);
                return byteslen;
        }
@@ -1155,65 +1181,71 @@ guint oid_string2encoded(const char *oid_str, guint8 **bytes) {
        return 0;
 }
 
-const gchar *oid_resolved_from_string(const gchar *oid_str) {
+gchar *oid_resolved_from_string(wmem_allocator_t *scope, const gchar *oid_str) {
        guint32     *subid_oid;
        guint        subid_oid_length;
-        const gchar *resolved;
+       gchar *resolved;
 
        subid_oid_length = oid_string2subid(NULL, oid_str, &subid_oid);
-       resolved         = oid_resolved(subid_oid_length, subid_oid);
+       resolved         = oid_resolved(scope, subid_oid_length, subid_oid);
 
        wmem_free(NULL, subid_oid);
 
        return resolved;
 }
 
-const gchar *oid_resolved(guint32 num_subids, guint32* subids) {
+gchar *oid_resolved(wmem_allocator_t *scope, guint32 num_subids, guint32* subids) {
        guint matched;
        guint left;
        oid_info_t* oid;
 
        if(! (subids && *subids <= 2 ))
-               return "*** Malformed OID ***";
+               return wmem_strdup(scope, "*** Malformed OID ***");
 
        oid = oid_get(num_subids, subids, &matched, &left);
 
        while (! oid->name ) {
                if (!(oid = oid->parent)) {
-                       return oid_subid2string(subids,num_subids);
+                       return oid_subid2string(scope, subids,num_subids);
                }
                left++;
                matched--;
        }
 
        if (left) {
-               return ep_strdup_printf("%s.%s",
-                                       oid->name ? oid->name : oid_subid2string(subids,matched),
-                                       oid_subid2string(&(subids[matched]),left));
+               gchar *ret,
+                         *str1 = oid_subid2string(NULL, subids,matched),
+                         *str2 = oid_subid2string(NULL, &(subids[matched]),left);
+
+               ret = wmem_strconcat(scope, oid->name ? oid->name : str1, ".", str2, NULL);
+               wmem_free(NULL, str1);
+               wmem_free(NULL, str2);
+               return ret;
        } else {
-               return oid->name ? oid->name : oid_subid2string(subids,matched);
+               return oid->name ? wmem_strdup(scope, oid->name) : oid_subid2string(scope, subids,matched);
        }
 }
 
-extern void oid_both(guint oid_len, guint32 *subids, const char** resolved_p, const char** numeric_p) {
-       *resolved_p = oid_resolved(oid_len,subids);
-       *numeric_p = oid_subid2string(subids,oid_len);
+extern void oid_both(wmem_allocator_t *scope, guint oid_len, guint32 *subids, gchar** resolved_p, gchar** numeric_p) {
+       *resolved_p = oid_resolved(scope, oid_len,subids);
+       *numeric_p = oid_subid2string(scope, subids,oid_len);
 }
 
-extern void oid_both_from_encoded(const guint8 *oid, gint oid_len, const char** resolved_p, const char** numeric_p) {
-       guint32* subids;
-       guint subids_len = oid_encoded2subid(oid, oid_len, &subids);
-       *resolved_p = oid_resolved(subids_len,subids);
-       *numeric_p = oid_subid2string(subids,subids_len);
+extern void oid_both_from_encoded(wmem_allocator_t *scope, const guint8 *oid, gint oid_len, gchar** resolved_p, gchar** numeric_p) {
+       guint32* subids = NULL;
+       guint subids_len = oid_encoded2subid(NULL, oid, oid_len, &subids);
+       *resolved_p = oid_resolved(scope, subids_len,subids);
+       *numeric_p = oid_subid2string(scope, subids,subids_len);
+       wmem_free(NULL, subids);
 }
 
-void oid_both_from_string(const gchar *oid_str, const char** resolved_p, const char** numeric_p) {
+void oid_both_from_string(wmem_allocator_t *scope, const gchar *oid_str, gchar** resolved_p, gchar** numeric_p) {
        guint32 *subids;
        guint    subids_len;
 
        subids_len  = oid_string2subid(NULL, oid_str, &subids);
-       *resolved_p = oid_resolved(subids_len,subids);
-       *numeric_p  = oid_subid2string(subids,subids_len);
+       *resolved_p = oid_resolved(scope, subids_len,subids);
+       *numeric_p  = oid_subid2string(scope, subids,subids_len);
        wmem_free(NULL, subids);
 }
 
@@ -1224,7 +1256,6 @@ extern gchar *
 oid_get_default_mib_path(void) {
 #ifdef HAVE_LIBSMI
        GString* path_str;
-       gchar *path_ret;
        char *path;
        guint i;
 
@@ -1251,7 +1282,7 @@ oid_get_default_mib_path(void) {
                g_string_append(path_str, PATH_SEPARATOR);
        }
        g_string_append_printf(path_str, "%s", path);
-       free (path);
+       smi_free(path);
 #endif
 
        for(i=0;i<num_smi_paths;i++) {
@@ -1261,9 +1292,7 @@ oid_get_default_mib_path(void) {
                g_string_append_printf(path_str,PATH_SEPARATOR "%s",smi_paths[i].name);
        }
 
-       path_ret = path_str->str;
-       g_string_free(path_str, FALSE);
-       return path_ret;
+       return g_string_free(path_str, FALSE);
 #else /* HAVE_LIBSMI */
         return g_strdup("");
 #endif
@@ -1271,18 +1300,19 @@ oid_get_default_mib_path(void) {
 
 #ifdef DEBUG_OIDS
 char* oid_test_a2b(guint32 num_subids, guint32* subids) {
-       guint8* sub2enc;
-       guint8* str2enc;
-       guint32* enc2sub;
+       guint8* sub2enc = NULL;
+       guint8* str2enc = NULL;
+       guint32* enc2sub = NULL;
        guint32* str2sub;
-       const char* sub2str = oid_subid2string(subids, num_subids);
-       guint sub2enc_len = oid_subid2encoded(num_subids, subids,&sub2enc);
-       guint enc2sub_len = oid_encoded2subid(sub2enc, sub2enc_len, &enc2sub);
-       const char* enc2str = oid_encoded2string(sub2enc, sub2enc_len);
-       guint str2enc_len = oid_string2encoded(sub2str,&str2enc);
+       char* ret;
+       char* sub2str = oid_subid2string(NULL, subids, num_subids);
+       guint sub2enc_len = oid_subid2encoded(NULL, num_subids, subids,&sub2enc);
+       guint enc2sub_len = oid_encoded2subid(NULL, sub2enc, sub2enc_len, &enc2sub);
+       char* enc2str = oid_encoded2string(NULL, sub2enc, sub2enc_len);
+       guint str2enc_len = oid_string2encoded(NULL, sub2str,&str2enc);
        guint str2sub_len = oid_string2subid(sub2str,&str2sub);
 
-       return ep_strdup_printf(
+       ret = wmem_strdup_printf(wmem_packet_scope(),
                                                        "oid_subid2string=%s \n"
                                                        "oid_subid2encoded=[%d]%s \n"
                                                        "oid_encoded2subid=%s \n "
@@ -1290,12 +1320,19 @@ char* oid_test_a2b(guint32 num_subids, guint32* subids) {
                                                        "oid_string2encoded=[%d]%s \n"
                                                        "oid_string2subid=%s \n "
                                                        ,sub2str
-                                                       ,sub2enc_len,bytestring_to_ep_str(sub2enc, sub2enc_len, ':')
-                                                       ,enc2sub ? oid_subid2string(enc2sub,enc2sub_len) : "-"
+                                                       ,sub2enc_len,bytestring_to_str(wmem_packet_scope(), sub2enc, sub2enc_len, ':')
+                                                       ,enc2sub ? oid_subid2string(wmem_packet_scope(), enc2sub,enc2sub_len) : "-"
                                                        ,enc2str
-                                                       ,str2enc_len,bytestring_to_ep_str(str2enc, str2enc_len, ':')
-                                                       ,str2sub ? oid_subid2string(str2sub,str2sub_len) : "-"
+                                                       ,str2enc_len,bytestring_to_str(wmem_packet_scope(), str2enc, str2enc_len, ':')
+                                                       ,str2sub ? oid_subid2string(wmem_packet_scope(), str2sub,str2sub_len) : "-"
                                                        );
+
+       wmem_free(NULL, sub2str);
+       wmem_free(NULL, enc2sub);
+       wmem_free(NULL, sub2enc);
+       wmem_free(NULL, str2enc);
+       wmem_free(NULL, enc2str);
+       return ret;
 }
 
 void add_oid_debug_subtree(oid_info_t* oid_info, proto_tree *tree) {
@@ -1303,7 +1340,7 @@ void add_oid_debug_subtree(oid_info_t* oid_info, proto_tree *tree) {
        static const char* key_types[] = {"OID_KEY_TYPE_WRONG","OID_KEY_TYPE_INTEGER",
                                                                                "OID_KEY_TYPE_FIXED_STRING","OID_KEY_TYPE_FIXED_BYTES","OID_KEY_TYPE_STRING",
                                                                                "OID_KEY_TYPE_BYTES","OID_KEY_TYPE_NSAP","OID_KEY_TYPE_OID","OID_KEY_TYPE_IPADDR"};
-       proto_item* pi = proto_tree_add_text(tree,NULL,0,0,
+       proto_item* pi = proto_tree_add_debug_text(tree,NULL,0,0,
        "OidInfo: Name='%s' sub-id=%u  kind=%s  hfid=%d",
        oid_info->name ? oid_info->name : "",
        oid_info->subid,
@@ -1313,7 +1350,7 @@ void add_oid_debug_subtree(oid_info_t* oid_info, proto_tree *tree) {
        oid_key_t* key;
 
        for(key = oid_info->key; key; key = key->next) {
-               proto_tree_add_text(pt,NULL,0,0,
+               proto_tree_add_debug_text(pt,NULL,0,0,
                "Key: name='%s' num_subids=%d type=%s",
                key->name,
                key->key_type <= OID_KEY_TYPE_IPADDR ? key_types[key->key_type] : "BROKEN"
@@ -1321,7 +1358,7 @@ void add_oid_debug_subtree(oid_info_t* oid_info, proto_tree *tree) {
        };
 
        if (oid_info->parent) {
-               pi = proto_tree_add_text(pt,NULL,0,0,"Parent:");
+               pi = proto_tree_add_debug_text(pt,NULL,0,0,"Parent:");
                pt = proto_item_add_subtree(pi,0);
                add_oid_debug_subtree(oid_info->parent, pt);
        }