ANNOUNCEMENT: Live Wireshark University & Allegro Packets online APAC Wireshark Training Session
April 17th, 2024 | 14:30-16:00 SGT (UTC+8) | Online

Wireshark-dev: Re: [Wireshark-dev] [libsmi] Re: Building libsmi from SVN as a .dll

From: Juergen Schoenwaelder <j.schoenwaelder@xxxxxxxxxxxxxxxxxxxx>
Date: Wed, 16 Apr 2008 16:15:16 +0200
On Wed, Apr 16, 2008 at 09:22:38AM +1000, Andrew Hood wrote:
 
> I think I have also tracked down one of the reasons wireshark crashes.

[...]
 
> At line 595 oids.c calls smiRenderOID to format the node. The implicit
> node is not completely filled in, and wireshark/tshark crashes in
> libsmi. This is not totally unreasonable since implicit nodes should
> never be seen.

A crash _inside_ libsmi is not really acceptable; smiRenderOID should 
return NULL if it can't do what the caller wants. So I created a sample
MIB and a little program to test this (see attachment) and I found
where things go wrong.

Attached is a patch which causes smiRenderOID() to render the OID
as a sequence of numbers in case it is called with SMI_RENDER_NAME
or SMI_RENDER_QUALIFIED and the label of the node is not known. But
this might not be the right thing to do; it might be better to
fail by returning NULL so that the caller gets control of what
should happen. On the other hand, we always append numeric OIDs.

/js

-- 
Juergen Schoenwaelder           Jacobs University Bremen gGmbH
Phone: +49 421 200 3587         Campus Ring 1, 28759 Bremen, Germany
Fax:   +49 421 200 3103         <http://www.jacobs-university.de/>
FOO-MIB DEFINITIONS ::= BEGIN

IMPORTS mib-2 FROM SNMPv2-SMI;

foo OBJECT IDENTIFIER ::= { mib-2 88 1 }

END
#include <stdio.h>
#include <smi.h>

static SmiSubid oid[] = {1, 3, 6, 1, 2, 1, 88};

static void
render(int flags)
{
    char *s;
    s = smiRenderOID(sizeof(oid)/sizeof(SmiSubid), oid, flags);
    printf(">%s<\n", s);
    smiFree(s);
}

int
main(int argc, char **argv)
{
    int i;

    smiInit(NULL);

    for (i = 1; i < argc; i++) {
	smiLoadModule(argv[i]);
    }
    
    render(0);
    render(SMI_RENDER_NAME);
    render(SMI_RENDER_QUALIFIED);

    return 0;
}
Index: smi.c
===================================================================
--- smi.c	(revision 8023)
+++ smi.c	(working copy)
@@ -1878,7 +1878,7 @@
     
     if (flags & (SMI_RENDER_NAME | SMI_RENDER_QUALIFIED)) {
 	nodePtr = smiGetNodeByOID(oidlen, oid);
-	if (nodePtr) {
+	if (nodePtr && nodePtr->name) {
 	    i = nodePtr->oidlen;
 	    if (flags & SMI_RENDER_QUALIFIED) {
 		modulePtr = smiGetNodeModule(nodePtr);