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.
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.