comparison arogue7/mdport.c @ 144:708bb2dea17c

arogue7, xrogue: prevent potential NULL dereferencing. It is possible for getpwuid() to fail and return NULL. Various md_get* functions now check for this.
author John "Elwin" Edwards
date Mon, 18 May 2015 10:53:22 -0400
parents b786053d2f37
children aac28331e71d
comparison
equal deleted inserted replaced
143:7faf4568c295 144:708bb2dea17c
233 #if !defined(_WIN32) && !defined(DJGPP) 233 #if !defined(_WIN32) && !defined(DJGPP)
234 struct passwd *pw; 234 struct passwd *pw;
235 235
236 pw = getpwuid(getuid()); 236 pw = getpwuid(getuid());
237 237
238 l = pw->pw_name; 238 if (pw != NULL)
239 l = pw->pw_name;
239 #endif 240 #endif
240 241
241 if ((l == NULL) || (*l == '\0')) 242 if ((l == NULL) || (*l == '\0'))
242 if ( (l = getenv("USERNAME")) == NULL ) 243 if ( (l = getenv("USERNAME")) == NULL )
243 if ( (l = getenv("LOGNAME")) == NULL ) 244 if ( (l = getenv("LOGNAME")) == NULL )
264 #else 265 #else
265 char slash = '/'; 266 char slash = '/';
266 struct passwd *pw; 267 struct passwd *pw;
267 pw = getpwuid(getuid()); 268 pw = getpwuid(getuid());
268 269
269 h = pw->pw_dir; 270 if (pw != NULL)
270 271 {
271 if (strcmp(h,"/") == 0) 272 h = pw->pw_dir;
272 h = NULL; 273 if (strcmp(h,"/") == 0)
274 h = NULL;
275 }
273 #endif 276 #endif
274 homedir[0] = 0; 277 homedir[0] = 0;
275 #ifdef _WIN32 278 #ifdef _WIN32
276 if(SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, 0, szPath))) 279 if(SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, 0, szPath)))
277 h = szPath; 280 h = szPath;
324 char *def = "C:\\COMMAND.COM"; 327 char *def = "C:\\COMMAND.COM";
325 #else 328 #else
326 char *def = "/bin/sh"; 329 char *def = "/bin/sh";
327 struct passwd *pw; 330 struct passwd *pw;
328 pw = getpwuid(getuid()); 331 pw = getpwuid(getuid());
329 s = pw->pw_shell; 332 if (pw != NULL)
333 s = pw->pw_shell;
330 #endif 334 #endif
331 if ((s == NULL) || (*s == '\0')) 335 if ((s == NULL) || (*s == '\0'))
332 if ( (s = getenv("COMSPEC")) == NULL) 336 if ( (s = getenv("COMSPEC")) == NULL)
333 if ( (s = getenv("SHELL")) == NULL) 337 if ( (s = getenv("SHELL")) == NULL)
334 if ( (s = getenv("SystemRoot")) == NULL) 338 if ( (s = getenv("SystemRoot")) == NULL)