Check argc before dereferencing argv[1], as we can launch xulrunner with no args if XUL_APP_FILE is set in the environment.

This commit is contained in:
bsmedberg%covad.net 2005-06-14 14:56:16 +00:00
Родитель 6752aa8bea
Коммит 49011d5b0c
1 изменённых файлов: 45 добавлений и 43 удалений

Просмотреть файл

@ -312,61 +312,63 @@ int main(int argc, char* argv[])
return 0; return 0;
} }
PRBool registerGlobal = IsArg(argv[1], "register-global"); if (argc > 1) {
PRBool registerUser = IsArg(argv[1], "register-user"); PRBool registerGlobal = IsArg(argv[1], "register-global");
if (registerGlobal || registerUser) { PRBool registerUser = IsArg(argv[1], "register-user");
if (argc != 2) { if (registerGlobal || registerUser) {
Usage(); if (argc != 2) {
return 1; Usage();
} return 1;
}
nsCOMPtr<nsIFile> regDir; nsCOMPtr<nsIFile> regDir;
nsresult rv = GetXULRunnerDir(argv[0], getter_AddRefs(regDir)); nsresult rv = GetXULRunnerDir(argv[0], getter_AddRefs(regDir));
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return 2; return 2;
return RegisterXULRunner(registerGlobal, regDir) ? 0 : 2; return RegisterXULRunner(registerGlobal, regDir) ? 0 : 2;
}
registerGlobal = IsArg(argv[1], "unregister-global");
registerUser = IsArg(argv[1], "unregister-user");
if (IsArg(argv[1], "unregister-global")) {
if (argc != 2) {
Usage();
return 1;
} }
nsCOMPtr<nsIFile> regDir; registerGlobal = IsArg(argv[1], "unregister-global");
nsresult rv = GetXULRunnerDir(argv[0], getter_AddRefs(regDir)); registerUser = IsArg(argv[1], "unregister-user");
if (NS_FAILED(rv)) if (IsArg(argv[1], "unregister-global")) {
if (argc != 2) {
Usage();
return 1;
}
nsCOMPtr<nsIFile> regDir;
nsresult rv = GetXULRunnerDir(argv[0], getter_AddRefs(regDir));
if (NS_FAILED(rv))
return 2; return 2;
UnregisterXULRunner(registerGlobal, regDir); UnregisterXULRunner(registerGlobal, regDir);
return 0; return 0;
}
if (IsArg(argv[1], "find-gre")) {
if (argc != 3) {
Usage();
return 1;
} }
char version[MAXPATHLEN]; if (IsArg(argv[1], "find-gre")) {
nsresult rv = GRE_GetGREPathForVersion(argv[2], version, MAXPATHLEN); if (argc != 3) {
if (NS_FAILED(rv)) Usage();
return 1; return 1;
}
printf("%s\n", version); char version[MAXPATHLEN];
return 0; nsresult rv = GRE_GetGREPathForVersion(argv[2], version, MAXPATHLEN);
} if (NS_FAILED(rv))
return 1;
if (IsArg(argv[1], "gre-version")) { printf("%s\n", version);
if (argc != 2) { return 0;
Usage();
return 1;
} }
printf("%s\n", GRE_BUILD_ID); if (IsArg(argv[1], "gre-version")) {
return 0; if (argc != 2) {
Usage();
return 1;
}
printf("%s\n", GRE_BUILD_ID);
return 0;
}
} }
geckoVersion = ParseVersion(GRE_BUILD_ID); geckoVersion = ParseVersion(GRE_BUILD_ID);