Fix NULL dereference of getpwuid() result and missing tfree()

This commit is contained in:
grayfox 2026-04-21 20:00:46 +02:00 committed by Holger Vogt
parent 72f2b8d6e1
commit 4cf82e6a52
2 changed files with 15 additions and 7 deletions

View File

@ -965,12 +965,15 @@ ngSpice_Init(SendChar* printfcn, SendStat* statusfcn, ControlledExit* ngspiceexi
struct passwd *pw;
pw = getpwuid(getuid());
s = tprintf("%s" DIR_PATHSEP "%s", pw->pw_dir, INITSTR);
if (pw) {
s = tprintf("%s" DIR_PATHSEP "%s", pw->pw_dir, INITSTR);
if (access(s, 0) == 0)
inp_source(s);
if (access(s, 0) == 0) {
inp_source(s);
}
tfree(s);
tfree(s);
}
}
#else /* ~ HAVE_PWD_H */
/* load user's initialisation file

View File

@ -2525,10 +2525,15 @@ Spice_Init(Tcl_Interp *interp)
struct passwd *pw;
pw = getpwuid(getuid());
s = tprintf("%s" DIR_PATHSEP "%s", pw->pw_dir, INITSTR);
if (pw) {
s = tprintf("%s" DIR_PATHSEP "%s", pw->pw_dir, INITSTR);
if (access(s, 0) == 0)
inp_source(s);
if (access(s, 0) == 0) {
inp_source(s);
}
tfree(s);
}
}
#else /* ~ HAVE_PWD_H */
{