comparison rogue3/mdport.c @ 6:9a2c0c60c386

Fix segfault on getpwuid failure
author edwarj4
date Fri, 16 Oct 2009 14:30:06 +0000
parents 527e2150eaf0
children d388234c4ce9
comparison
equal deleted inserted replaced
5:e361fbca47ec 6:9a2c0c60c386
442 l = mybuffer; 442 l = mybuffer;
443 #elif defined(HAVE_GETPWUID)&& !defined(__DJGPP__) 443 #elif defined(HAVE_GETPWUID)&& !defined(__DJGPP__)
444 struct passwd *pw; 444 struct passwd *pw;
445 445
446 pw = getpwuid(getuid()); 446 pw = getpwuid(getuid());
447 447 /* Don't segfault if getpwuid fails (and the thing is wildly possible) */
448 l = pw->pw_name; 448 if (pw != NULL)
449 l = pw->pw_name;
450 else
451 l = NULL;
449 #endif 452 #endif
450 453
451 if ((l == NULL) || (*l == '\0')) 454 if ((l == NULL) || (*l == '\0'))
452 if ( (l = getenv("USERNAME")) == NULL ) 455 if ( (l = getenv("USERNAME")) == NULL )
453 if ( (l = getenv("LOGNAME")) == NULL ) 456 if ( (l = getenv("LOGNAME")) == NULL )
473 char slash = '\\'; 476 char slash = '\\';
474 #else 477 #else
475 char slash = '/'; 478 char slash = '/';
476 struct passwd *pw; 479 struct passwd *pw;
477 pw = getpwuid(getuid()); 480 pw = getpwuid(getuid());
478 481 /* Don't segfault if getpwuid fails */
479 h = pw->pw_dir; 482 if (pw != NULL)
483 h = pw->pw_dir;
484 else
485 h = NULL;
480 486
481 if (strcmp(h,"/") == 0) 487 if (strcmp(h,"/") == 0)
482 h = NULL; 488 h = NULL;
483 #endif 489 #endif
484 homedir[0] = 0; 490 homedir[0] = 0;
538 char *def = "C:\\COMMAND.COM"; 544 char *def = "C:\\COMMAND.COM";
539 #else 545 #else
540 char *def = "/bin/sh"; 546 char *def = "/bin/sh";
541 struct passwd *pw; 547 struct passwd *pw;
542 pw = getpwuid(getuid()); 548 pw = getpwuid(getuid());
543 s = pw->pw_shell; 549 /* don't segfault if getpwuid fails */
550 if (pw != NULL)
551 s = pw->pw_shell;
552 else
553 s = NULL;
544 #endif 554 #endif
545 if ((s == NULL) || (*s == '\0')) 555 if ((s == NULL) || (*s == '\0'))
546 if ( (s = getenv("COMSPEC")) == NULL) 556 if ( (s = getenv("COMSPEC")) == NULL)
547 if ( (s = getenv("SHELL")) == NULL) 557 if ( (s = getenv("SHELL")) == NULL)
548 if ( (s = getenv("SystemRoot")) == NULL) 558 if ( (s = getenv("SystemRoot")) == NULL)