From: John Hodge (sonata) Date: Tue, 5 Mar 2013 07:39:51 +0000 (+0800) Subject: Usermode/init - Fixed a couple of NULL dereferences X-Git-Tag: rel0.15~537^2~3 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=b9bf2c8b90b846a8cf11b57071765f24dd37fd4f;p=tpg%2Facess2.git Usermode/init - Fixed a couple of NULL dereferences --- diff --git a/Usermode/Applications/init_src/main.c b/Usermode/Applications/init_src/main.c index a3d737d9..0dbbff14 100644 --- a/Usermode/Applications/init_src/main.c +++ b/Usermode/Applications/init_src/main.c @@ -54,7 +54,7 @@ int main(int argc, char *argv[]) // No inittab file found, default to: _SysDebug("inittab '%s' is invalid, falling back to one VT", gsInittabPath); - #if 0 + #if 1 for( ;; ) { int pid = SpawnCommand(0, 1, 1, (char *[]){DEFAULT_SHELL, NULL}); @@ -157,7 +157,8 @@ char *ReadQuotedString(FILE *FP) retstr[pos++] = ch; } } - retstr[pos] = '\0'; + if( retstr ) + retstr[pos] = '\0'; return retstr; } @@ -179,6 +180,12 @@ char **ReadCommand(FILE *FP) } ret[pos++] = arg; } while(arg != NULL); + + if( pos == 0 ) + { + free(ret); + return NULL; + } ret[pos] = NULL; return ret; } @@ -196,6 +203,7 @@ void FreeCommand(char **Command) int ProcessInittab(const char *Path) { + int line_num = 0; FILE *fp = fopen(Path, "r"); if( !fp ) @@ -205,6 +213,8 @@ int ProcessInittab(const char *Path) { char cmdbuf[64+1]; + line_num ++; + int rv; if( (rv = fscanf(fp, "%64s%*[ \t]", &cmdbuf)) != 1 ) { _SysDebug("fscanf rv %i != exp 1", rv); @@ -290,13 +300,17 @@ int ProcessInittab(const char *Path) fscanf(fp, " "); continue; lineError: - _SysDebug("label lineError: goto'd"); + _SysDebug("label lineError: goto'd - line %i, cmdbuf='%s'", line_num, cmdbuf); while( !feof(fp) && fgetc(fp) != '\n' ) ; continue ; } fclose(fp); + + if( gpInitPrograms == NULL ) + return 2; + return 0; }