Bug 432342 - snmp_parse_args broken for -c option
Summary: snmp_parse_args broken for -c option
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: net-snmp
Version: 7
Hardware: i386
OS: Linux
low
high
Target Milestone: ---
Assignee: Jan Safranek
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2008-02-11 13:58 UTC by Sumit Pandya
Modified: 2008-02-11 15:21 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2008-02-11 15:21:52 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Sumit Pandya 2008-02-11 13:58:51 UTC
Description of problem:
A simple program will generate SIGSEGV for mentioned summary

Version-Release number of selected component (if applicable):
net-snmp-5.4-16.fc7

How reproducible:
Compile (gcc snmptest.c -lnetsnmp) and run following program
#include <net-snmp/net-snmp-config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <net-snmp/net-snmp-includes.h>

int main(int argc,char *argv[])
{
        netsnmp_session session;
        int nArgCount=6;
        char *aArgList[] = {"snmpwalk", "-v2c", "-
c", "public", "localhost", "wmanIfBsSsMacAddress", (char*)NULL};

        snmp_debug_init();
        snmp_set_do_debugging(1);
        snmp_parse_args(nArgCount, aArgList, &session, NULL, NULL);
        //snmp_parse_args(argc, argv, &session, NULL, NULL);

        return 0;
}

Steps to Reproduce:
1. Compile and run above program will generate SIGSEGV
2. Comment previous snmp_parse_args and Uncomment subsequent snmp_parse_args. 
Then compile and run program with arguments on command-line will work
3.
  
Actual results:


Expected results:
It should be able to parse "-c" argument

Additional info:
I tried almost all permutation and combination of passing "-c" option like "-
cpublic"; "-c=public" ; "-c=private" "-c", "private"; "--c=public"
If you remove "-c" option then snmp_parse_args API give proper message
No community name specified.

Comment 1 Jan Safranek 2008-02-11 15:21:52 UTC
snmp library tries to modify the argv[] strings. You used string literals, which
are in read-only memory, but snmp_parse_args tries to modify them -> crash. You
should strdup() the literals before passing them to snmp_parse_args.


Note You need to log in before you can comment on or make changes to this bug.