snmp getpwuid leak
This commit is contained in:
parent
73129b96d9
commit
947128339c
2 changed files with 38 additions and 1 deletions
|
|
@ -341,7 +341,12 @@ main(int argc,
|
||||||
char *argv0 = argv[0];
|
char *argv0 = argv[0];
|
||||||
clixon_handle h;
|
clixon_handle h;
|
||||||
int logdst = CLIXON_LOG_STDERR;
|
int logdst = CLIXON_LOG_STDERR;
|
||||||
|
#if 1
|
||||||
|
struct passwd pw = {0,};
|
||||||
|
struct passwd *pwresult = NULL;
|
||||||
|
#else
|
||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
|
#endif
|
||||||
yang_stmt *yspec = NULL;
|
yang_stmt *yspec = NULL;
|
||||||
char *str;
|
char *str;
|
||||||
uint32_t id;
|
uint32_t id;
|
||||||
|
|
@ -358,6 +363,11 @@ main(int argc,
|
||||||
enum format_enum config_dump_format = FORMAT_XML;
|
enum format_enum config_dump_format = FORMAT_XML;
|
||||||
int print_version = 0;
|
int print_version = 0;
|
||||||
int32_t d;
|
int32_t d;
|
||||||
|
#if 1
|
||||||
|
char *buf = NULL;
|
||||||
|
size_t bufsize = 0;
|
||||||
|
int err;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Create handle */
|
/* Create handle */
|
||||||
if ((h = clixon_handle_init()) == NULL)
|
if ((h = clixon_handle_init()) == NULL)
|
||||||
|
|
@ -369,12 +379,35 @@ main(int argc,
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
/* Set username to clixon handle. Use in all communication to backend */
|
/* Set username to clixon handle. Use in all communication to backend */
|
||||||
|
#if 1
|
||||||
|
{
|
||||||
|
bufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
|
||||||
|
if (bufsize == -1){
|
||||||
|
bufsize = 16384;
|
||||||
|
}
|
||||||
|
if ((buf = malloc(bufsize)) == NULL){
|
||||||
|
clixon_err(OE_UNIX, errno, "malloc");
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
err = getpwuid_r(getuid(), &pw, buf, bufsize, &pwresult);
|
||||||
|
if (pwresult == NULL) {
|
||||||
|
if (err == 0)
|
||||||
|
clixon_err(OE_UNIX, errno, "getpwuid_r");
|
||||||
|
else
|
||||||
|
clixon_err(OE_UNIX, err, "getpwuid_r");
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (clicon_username_set(h, pw.pw_name) < 0)
|
||||||
|
goto done;
|
||||||
|
#else
|
||||||
if ((pw = getpwuid(getuid())) == NULL){
|
if ((pw = getpwuid(getuid())) == NULL){
|
||||||
clixon_err(OE_UNIX, errno, "getpwuid");
|
clixon_err(OE_UNIX, errno, "getpwuid");
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
if (clicon_username_set(h, pw->pw_name) < 0)
|
if (clicon_username_set(h, pw->pw_name) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
#endif
|
||||||
while ((c = getopt(argc, argv, SNMP_OPTS)) != -1)
|
while ((c = getopt(argc, argv, SNMP_OPTS)) != -1)
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'h' : /* help */
|
case 'h' : /* help */
|
||||||
|
|
@ -592,6 +625,10 @@ main(int argc,
|
||||||
ok:
|
ok:
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
|
#if 1
|
||||||
|
if (buf)
|
||||||
|
free(buf);
|
||||||
|
#endif
|
||||||
clixon_log_init(h, __PROGRAM__, LOG_INFO, 0); /* Log on syslog no stderr */
|
clixon_log_init(h, __PROGRAM__, LOG_INFO, 0); /* Log on syslog no stderr */
|
||||||
clixon_log(h, LOG_NOTICE, "%s: %u Terminated", __PROGRAM__, getpid());
|
clixon_log(h, LOG_NOTICE, "%s: %u Terminated", __PROGRAM__, getpid());
|
||||||
snmp_terminate(h);
|
snmp_terminate(h);
|
||||||
|
|
|
||||||
|
|
@ -231,7 +231,7 @@ if $SNMPCHECK; then
|
||||||
snmpgetnextstr="$(type -p snmpgetnext) -c public -v2c localhost "
|
snmpgetnextstr="$(type -p snmpgetnext) -c public -v2c localhost "
|
||||||
if [ $valgrindtest -ne 0 ]; then
|
if [ $valgrindtest -ne 0 ]; then
|
||||||
# To avoid "Timeout: No Response from localhost" from netsnmp/snmpd set timeout to 10s
|
# To avoid "Timeout: No Response from localhost" from netsnmp/snmpd set timeout to 10s
|
||||||
snmptable="$(type -p snmptable) -c public -v2c localhost -t 10 "
|
snmptable="$(type -p snmptable) -c public -t 10 -v2c localhost "
|
||||||
snmpwalk="$(type -p snmpwalk) -c public -t 10 -v2c localhost "
|
snmpwalk="$(type -p snmpwalk) -c public -t 10 -v2c localhost "
|
||||||
else
|
else
|
||||||
snmptable="$(type -p snmptable) -c public -v2c localhost "
|
snmptable="$(type -p snmptable) -c public -v2c localhost "
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue