Mercurial > hg > early-roguelike
comparison xrogue/state.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 | 7faf4568c295 |
children | 1af259ac4ed2 |
comparison
equal
deleted
inserted
replaced
143:7faf4568c295 | 144:708bb2dea17c |
---|---|
2992 #if !defined(_WIN32) && !defined(DJGPP) | 2992 #if !defined(_WIN32) && !defined(DJGPP) |
2993 struct passwd *pw; | 2993 struct passwd *pw; |
2994 | 2994 |
2995 pw = getpwuid(getuid()); | 2995 pw = getpwuid(getuid()); |
2996 | 2996 |
2997 l = pw->pw_name; | 2997 if (pw != NULL) |
2998 l = pw->pw_name; | |
2998 #endif | 2999 #endif |
2999 | 3000 |
3000 if ((l == NULL) || (*l == '\0')) | 3001 if ((l == NULL) || (*l == '\0')) |
3001 if ( (l = getenv("USERNAME")) == NULL ) | 3002 if ( (l = getenv("USERNAME")) == NULL ) |
3002 if ( (l = getenv("LOGNAME")) == NULL ) | 3003 if ( (l = getenv("LOGNAME")) == NULL ) |
3023 #else | 3024 #else |
3024 char slash = '/'; | 3025 char slash = '/'; |
3025 struct passwd *pw; | 3026 struct passwd *pw; |
3026 pw = getpwuid(getuid()); | 3027 pw = getpwuid(getuid()); |
3027 | 3028 |
3028 h = pw->pw_dir; | 3029 if (pw != NULL) |
3029 | 3030 { |
3030 if (strcmp(h,"/") == 0) | 3031 h = pw->pw_dir; |
3031 h = NULL; | 3032 if (strcmp(h,"/") == 0) |
3033 h = NULL; | |
3034 } | |
3032 #endif | 3035 #endif |
3033 homedir[0] = 0; | 3036 homedir[0] = 0; |
3034 | 3037 |
3035 #ifdef _WIN32 | 3038 #ifdef _WIN32 |
3036 if(SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, 0, szPath))) | 3039 if(SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, 0, szPath))) |
3122 char *def = "C:\\COMMAND.COM"; | 3125 char *def = "C:\\COMMAND.COM"; |
3123 #else | 3126 #else |
3124 char *def = "/bin/sh"; | 3127 char *def = "/bin/sh"; |
3125 struct passwd *pw; | 3128 struct passwd *pw; |
3126 pw = getpwuid(getuid()); | 3129 pw = getpwuid(getuid()); |
3127 s = pw->pw_shell; | 3130 if (pw != NULL) |
3131 s = pw->pw_shell; | |
3128 #endif | 3132 #endif |
3129 if ((s == NULL) || (*s == '\0')) | 3133 if ((s == NULL) || (*s == '\0')) |
3130 if ( (s = getenv("COMSPEC")) == NULL) | 3134 if ( (s = getenv("COMSPEC")) == NULL) |
3131 if ( (s = getenv("SHELL")) == NULL) | 3135 if ( (s = getenv("SHELL")) == NULL) |
3132 if ( (s = getenv("SystemRoot")) == NULL) | 3136 if ( (s = getenv("SystemRoot")) == NULL) |