bool FakeInputStream::CheckTest(nsAString& aResult) { return !NS_tstrcmp(aResult.BeginReading(), NS_ConvertASCIItoUTF16(mTest->mResult).BeginReading()) ? true : false; }
int CVE_2014_1496_thunderbird24_1_0_DoUpdate() { NS_tchar manifest[MAXPATHLEN]; NS_tsnprintf(manifest, sizeof(manifest)/sizeof(manifest[0]), NS_T("%s/update.manifest"), gSourcePath); // extract the manifest int rv = gArchiveReader.ExtractFile("updatev2.manifest", manifest); if (rv) { rv = gArchiveReader.ExtractFile("update.manifest", manifest); if (rv) { LOG(("CVE_2014_1496_thunderbird24_1_0_DoUpdate: error extracting manifest file")); return rv; } } NS_tchar *rb = GetManifestContents(manifest); if (rb == NULL) { LOG(("CVE_2014_1496_thunderbird24_1_0_DoUpdate: error opening manifest file: " LOG_S, manifest)); return READ_ERROR; } ActionList list; NS_tchar *line; bool isFirstAction = true; while((line = mstrtok(kNL, &rb)) != 0) { // skip comments if (*line == NS_T('#')) continue; NS_tchar *token = mstrtok(kWhitespace, &line); if (!token) { LOG(("CVE_2014_1496_thunderbird24_1_0_DoUpdate: token not found in manifest")); return PARSE_ERROR; } if (isFirstAction && NS_tstrcmp(token, NS_T("type")) == 0) { const NS_tchar *type = mstrtok(kQuote, &line); LOG(("UPDATE TYPE " LOG_S, type)); if (NS_tstrcmp(type, NS_T("complete")) == 0) { rv = AddPreCompleteActions(&list); if (rv) return rv; } isFirstAction = false; continue; } isFirstAction = false; Action *action = NULL; if (NS_tstrcmp(token, NS_T("remove")) == 0) { // rm file action = new RemoveFile(); } else if (NS_tstrcmp(token, NS_T("rmdir")) == 0) { // rmdir if empty action = new RemoveDir(); } else if (NS_tstrcmp(token, NS_T("rmrfdir")) == 0) { // rmdir recursive const NS_tchar *reldirpath = mstrtok(kQuote, &line); if (!reldirpath) return PARSE_ERROR; if (reldirpath[NS_tstrlen(reldirpath) - 1] != NS_T('/')) return PARSE_ERROR; rv = add_dir_entries(reldirpath, &list); if (rv) return rv; continue; } else if (NS_tstrcmp(token, NS_T("add")) == 0) { action = new AddFile(); } else if (NS_tstrcmp(token, NS_T("patch")) == 0) { action = new PatchFile(); } else if (NS_tstrcmp(token, NS_T("add-if")) == 0) { // Add if exists action = new AddIfFile(); } else if (NS_tstrcmp(token, NS_T("patch-if")) == 0) { // Patch if exists action = new PatchIfFile(); } else if (NS_tstrcmp(token, NS_T("add-cc")) == 0) { // no longer supported continue; } else { LOG(("CVE_2014_1496_thunderbird24_1_0_DoUpdate: unknown token: " LOG_S, token)); return PARSE_ERROR; } if (!action) return BAD_ACTION_ERROR; rv = action->Parse(line); if (rv) return rv; list.Append(action); } rv = list.Prepare(); if (rv) return rv; rv = list.Execute(); list.Finish(rv); return rv; }
int NS_main(int argc, NS_tchar **argv) { if (argc < 3) { fprintf(stderr, \ "\n" \ "Application Update Service Test Helper\n" \ "\n" \ "Usage: WORKINGDIR INFILE OUTFILE -s SECONDS [FILETOLOCK]\n" \ " or: WORKINGDIR LOGFILE [ARG2 ARG3...]\n" \ " or: signature-check filepath\n" \ " or: setup-symlink dir1 dir2 file symlink\n" \ " or: remove-symlink dir1 dir2 file symlink\n" \ " or: check-symlink symlink\n" \ "\n" \ " WORKINGDIR \tThe relative path to the working directory to use.\n" \ " INFILE \tThe relative path from the working directory for the file to\n" \ " \tread actions to perform such as finish.\n" \ " OUTFILE \tThe relative path from the working directory for the file to\n" \ " \twrite status information.\n" \ " SECONDS \tThe number of seconds to sleep.\n" \ " FILETOLOCK \tThe relative path from the working directory to an existing\n" \ " \tfile to open exlusively.\n" \ " \tOnly available on Windows platforms and silently ignored on\n" \ " \tother platforms.\n" \ " LOGFILE \tThe relative path from the working directory to log the\n" \ " \tcommand line arguments.\n" \ " ARG2 ARG3...\tArguments to write to the LOGFILE after the preceding command\n" \ " \tline arguments.\n" \ "\n" \ "Note: All paths must be relative.\n" \ "\n"); return 1; } if (!NS_tstrcmp(argv[1], NS_T("check-signature"))) { #ifdef XP_WIN if (ERROR_SUCCESS == VerifyCertificateTrustForFile(argv[2])) { return 0; } else { return 1; } #else // Not implemented on non-Windows platforms return 1; #endif } if (!NS_tstrcmp(argv[1], NS_T("setup-symlink"))) { #ifdef XP_UNIX NS_tchar path[MAXPATHLEN]; NS_tsnprintf(path, sizeof(path)/sizeof(path[0]), NS_T("%s/%s"), NS_T("/tmp"), argv[2]); mkdir(path, 0755); NS_tsnprintf(path, sizeof(path)/sizeof(path[0]), NS_T("%s/%s/%s"), NS_T("/tmp"), argv[2], argv[3]); mkdir(path, 0755); NS_tsnprintf(path, sizeof(path)/sizeof(path[0]), NS_T("%s/%s/%s/%s"), NS_T("/tmp"), argv[2], argv[3], argv[4]); FILE * file = NS_tfopen(path, NS_T("w")); if (file) { NS_tfputs(NS_T("test"), file); fclose(file); } symlink(path, argv[5]); NS_tsnprintf(path, sizeof(path)/sizeof(path[0]), NS_T("%s/%s"), NS_T("/tmp"), argv[2]); if (argc > 6 && !NS_tstrcmp(argv[6], NS_T("change-perm"))) { chmod(path, 0644); } return 0; #else // Not implemented on non-Unix platforms return 1; #endif } if (!NS_tstrcmp(argv[1], NS_T("remove-symlink"))) { #ifdef XP_UNIX NS_tchar path[MAXPATHLEN]; NS_tsnprintf(path, sizeof(path)/sizeof(path[0]), NS_T("%s/%s"), NS_T("/tmp"), argv[2]); chmod(path, 0755); NS_tsnprintf(path, sizeof(path)/sizeof(path[0]), NS_T("%s/%s/%s/%s"), NS_T("/tmp"), argv[2], argv[3], argv[4]); unlink(path); NS_tsnprintf(path, sizeof(path)/sizeof(path[0]), NS_T("%s/%s/%s"), NS_T("/tmp"), argv[2], argv[3]); rmdir(path); NS_tsnprintf(path, sizeof(path)/sizeof(path[0]), NS_T("%s/%s"), NS_T("/tmp"), argv[2]); rmdir(path); return 0; #else // Not implemented on non-Unix platforms return 1; #endif } if (!NS_tstrcmp(argv[1], NS_T("check-symlink"))) { #ifdef XP_UNIX struct stat ss; lstat(argv[2], &ss); return S_ISLNK(ss.st_mode) ? 0 : 1; #else // Not implemented on non-Unix platforms return 1; #endif } if (!NS_tstrcmp(argv[1], NS_T("wait-for-service-stop"))) { #ifdef XP_WIN const int maxWaitSeconds = NS_ttoi(argv[3]); LPCWSTR serviceName = argv[2]; DWORD serviceState = WaitForServiceStop(serviceName, maxWaitSeconds); if (SERVICE_STOPPED == serviceState) { return 0; } else { return serviceState; } #else // Not implemented on non-Windows platforms return 1; #endif } if (!NS_tstrcmp(argv[1], NS_T("wait-for-application-exit"))) { #ifdef XP_WIN const int maxWaitSeconds = NS_ttoi(argv[3]); LPCWSTR application = argv[2]; DWORD ret = WaitForProcessExit(application, maxWaitSeconds); if (ERROR_SUCCESS == ret) { return 0; } else if (WAIT_TIMEOUT == ret) { return 1; } else { return 2; } #else // Not implemented on non-Windows platforms return 1; #endif } int i = 0; if (NS_tchdir(argv[1]) != 0) { return 1; } // File in use test helper section if (!NS_tstrcmp(argv[4], NS_T("-s"))) { NS_tchar *cwd = NS_tgetcwd(nullptr, 0); NS_tchar inFilePath[MAXPATHLEN]; NS_tsnprintf(inFilePath, sizeof(inFilePath)/sizeof(inFilePath[0]), NS_T("%s/%s"), cwd, argv[2]); NS_tchar outFilePath[MAXPATHLEN]; NS_tsnprintf(outFilePath, sizeof(outFilePath)/sizeof(outFilePath[0]), NS_T("%s/%s"), cwd, argv[3]); int seconds = NS_ttoi(argv[5]); #ifdef XP_WIN HANDLE hFile = INVALID_HANDLE_VALUE; if (argc == 7) { hFile = CreateFileW(argv[6], DELETE | GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, 0, nullptr); if (hFile == INVALID_HANDLE_VALUE) { WriteMsg(outFilePath, "error_locking"); return 1; } } WriteMsg(outFilePath, "sleeping"); while (!CheckMsg(inFilePath, "finish\n") && i++ <= seconds) { Sleep(1000); } if (argc == 7) { CloseHandle(hFile); } #else WriteMsg(outFilePath, "sleeping"); while (!CheckMsg(inFilePath, "finish\n") && i++ <= seconds) { sleep(1); } #endif WriteMsg(outFilePath, "finished"); return 0; } // Command line argument test helper section NS_tchar logFilePath[MAXPATHLEN]; NS_tsnprintf(logFilePath, sizeof(logFilePath)/sizeof(logFilePath[0]), NS_T("%s"), argv[2]); FILE* logFP = NS_tfopen(logFilePath, NS_T("wb")); for (i = 1; i < argc; ++i) { fprintf(logFP, LOG_S "\n", argv[i]); } fclose(logFP); logFP = nullptr; return 0; }