Bug 432342

Summary: snmp_parse_args broken for -c option
Product: [Fedora] Fedora Reporter: Sumit Pandya <sumit>
Component: net-snmpAssignee: Jan Safranek <jsafrane>
Status: CLOSED NOTABUG QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: high Docs Contact:
Priority: low    
Version: 7   
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2008-02-11 15:21:52 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

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.