Bug 432342 - snmp_parse_args broken for -c option
snmp_parse_args broken for -c option
Product: Fedora
Classification: Fedora
Component: net-snmp (Show other bugs)
i386 Linux
low Severity high
: ---
: ---
Assigned To: Jan Safranek
Fedora Extras Quality Assurance
Depends On:
  Show dependency treegraph
Reported: 2008-02-11 08:58 EST by Sumit Pandya
Modified: 2008-02-11 10:21 EST (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2008-02-11 10:21:52 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Sumit Pandya 2008-02-11 08:58:51 EST
Description of problem:
A simple program will generate SIGSEGV for mentioned summary

Version-Release number of selected component (if applicable):

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_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
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 10:21:52 EST
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.