Changeset 2860 in kBuild
- Timestamp:
- Sep 1, 2016 4:55:07 PM (9 years ago)
- Location:
- trunk/src/kWorker
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kWorker/Makefile.kmk
r2858 r2860 64 64 nt/ntstat.c \ 65 65 nt/ntunlink.c \ 66 nt/kFsCache.c 66 nt/kFsCache.c \ 67 quote_argv.c 67 68 kbuild_version.c_DEFS = KBUILD_SVN_REV=$(KBUILD_SVN_REV) 68 69 -
trunk/src/kWorker/kWorker.c
r2859 r2860 47 47 48 48 #include "nt/kFsCache.h" 49 #include "quote_argv.h" 49 50 50 51 … … 4308 4309 4309 4310 4311 /** 4312 * Creates a correctly quoted ANSI command line string from the given argv. 4313 * 4314 * @returns Pointer to the command line. 4315 * @param cArgs Number of arguments. 4316 * @param papszArgs The argument vector. 4317 * @param fWatcomBrainDamange Whether to apply watcom rules while quoting. 4318 * @param pcbCmdLine Where to return the command line length, 4319 * including one terminator. 4320 */ 4321 static char *kwSandboxInitCmdLineFromArgv(KU32 cArgs, const char **papszArgs, KBOOL fWatcomBrainDamange, KSIZE *pcbCmdLine) 4322 { 4323 KU32 i; 4324 KSIZE cbCmdLine; 4325 char *pszCmdLine; 4326 4327 /* Make a copy of the argument vector that we'll be quoting. */ 4328 char **papszQuotedArgs = alloca(sizeof(papszArgs[0]) * (cArgs + 1)); 4329 kHlpMemCopy(papszQuotedArgs, papszArgs, sizeof(papszArgs[0]) * (cArgs + 1)); 4330 4331 /* Quote the arguments that need it. */ 4332 quote_argv(cArgs, papszQuotedArgs, fWatcomBrainDamange, 0 /*leak*/); 4333 4334 /* figure out cmd line length. */ 4335 cbCmdLine = 0; 4336 for (i = 0; i < cArgs; i++) 4337 cbCmdLine += strlen(papszQuotedArgs[i]) + 1; 4338 *pcbCmdLine = cbCmdLine; 4339 4340 pszCmdLine = (char *)kHlpAlloc(cbCmdLine + 1); 4341 if (pszCmdLine) 4342 { 4343 char *psz = kHlpStrPCopy(pszCmdLine, papszQuotedArgs[0]); 4344 if (papszQuotedArgs[0] != papszArgs[0]) 4345 free(papszQuotedArgs[0]); 4346 4347 for (i = 1; i < cArgs; i++) 4348 { 4349 *psz++ = ' '; 4350 psz = kHlpStrPCopy(psz, papszQuotedArgs[i]); 4351 if (papszQuotedArgs[i] != papszArgs[i]) 4352 free(papszQuotedArgs[i]); 4353 } 4354 kHlpAssert((KSIZE)(&psz[1] - pszCmdLine) == cbCmdLine); 4355 4356 *psz++ = '\0'; 4357 *psz++ = '\0'; 4358 } 4359 4360 return pszCmdLine; 4361 } 4362 4363 4310 4364 4311 4365 static int kwSandboxInit(PKWSANDBOX pSandbox, PKWTOOL pTool, 4312 KU32 cArgs, const char **papszArgs, K U32 cbArgs,4366 KU32 cArgs, const char **papszArgs, KBOOL fWatcomBrainDamange, 4313 4367 KU32 cEnvVars, const char **papszEnvVars) 4314 4368 { 4315 4369 PPEB pPeb = kwSandboxGetProcessEnvironmentBlock(); 4316 char *psz;4317 4370 wchar_t *pwcPool; 4318 4371 KSIZE cbStrings; 4319 4372 KSIZE cwc; 4373 KSIZE cbCmdLine; 4320 4374 KU32 i; 4321 4375 4322 4376 /* Simple stuff. */ 4323 g_Sandbox.rcExitCode = 256; 4324 g_Sandbox.pTool = pTool; 4325 g_Sandbox.idMainThread = GetCurrentThreadId(); 4326 g_Sandbox.TibMainThread = *(PNT_TIB)NtCurrentTeb(); 4327 g_Sandbox.pgmptr = (char *)pTool->pszPath; 4328 g_Sandbox.wpgmptr = (wchar_t *)pTool->pwszPath; 4329 g_Sandbox.cArgs = cArgs; 4330 g_Sandbox.papszArgs = (char **)papszArgs; 4331 4332 /* 4333 * Create a command line from the given argv. 4334 * ASSUME that it's correctly quoted by quote_argv.c already. 4335 */ 4336 pSandbox->pszCmdLine = psz = (char *)kHlpAlloc(cbArgs + 1); 4337 if (!psz) 4377 pSandbox->rcExitCode = 256; 4378 pSandbox->pTool = pTool; 4379 pSandbox->idMainThread = GetCurrentThreadId(); 4380 pSandbox->TibMainThread = *(PNT_TIB)NtCurrentTeb(); 4381 pSandbox->pgmptr = (char *)pTool->pszPath; 4382 pSandbox->wpgmptr = (wchar_t *)pTool->pwszPath; 4383 pSandbox->cArgs = cArgs; 4384 pSandbox->papszArgs = (char **)papszArgs; 4385 pSandbox->pszCmdLine = kwSandboxInitCmdLineFromArgv(cArgs, papszArgs, fWatcomBrainDamange, &cbCmdLine); 4386 if (!pSandbox->pszCmdLine) 4338 4387 return KERR_NO_MEMORY; 4339 psz = kHlpStrPCopy(psz, papszArgs[0]);4340 for (i = 1; i < cArgs; i++)4341 {4342 *psz++ = ' ';4343 psz = kHlpStrPCopy(psz, papszArgs[i]);4344 }4345 kHlpAssert((KSIZE)(&psz[1] - pSandbox->pszCmdLine) == cbArgs);4346 psz[0] = '\0';4347 psz[1] = '\0';4348 4388 4349 4389 /* … … 4351 4391 * We assume each ANSI char requires a surrogate pair in the UTF-16 variant. 4352 4392 */ 4353 pSandbox->papwszArgs = (wchar_t **)kHlpAlloc(sizeof(wchar_t *) * (pSandbox->cArgs + 2) + cb Args* 2 * sizeof(wchar_t));4393 pSandbox->papwszArgs = (wchar_t **)kHlpAlloc(sizeof(wchar_t *) * (pSandbox->cArgs + 2) + cbCmdLine * 2 * sizeof(wchar_t)); 4354 4394 if (!pSandbox->papwszArgs) 4355 4395 return KERR_NO_MEMORY; … … 4368 4408 * Convert the commandline string to UTF-16, same pessimistic approach as above. 4369 4409 */ 4370 cbStrings = (cb Args+ 1) * 2 * sizeof(wchar_t);4410 cbStrings = (cbCmdLine + 1) * 2 * sizeof(wchar_t); 4371 4411 pSandbox->pwszCmdLine = kHlpAlloc(cbStrings); 4372 4412 if (!pSandbox->pwszCmdLine) … … 4415 4455 4416 4456 4417 static int kwSandboxExec(PKWTOOL pTool, KU32 cArgs, const char **papszArgs, K U32 cbArgs,4457 static int kwSandboxExec(PKWTOOL pTool, KU32 cArgs, const char **papszArgs, KBOOL fWatcomBrainDamange, 4418 4458 KU32 cEnvVars, const char **papszEnvVars) 4419 4459 { … … 4424 4464 * Initialize the sandbox environment. 4425 4465 */ 4426 rc = kwSandboxInit(&g_Sandbox, pTool, cArgs, papszArgs, cbArgs, cEnvVars, papszEnvVars);4466 rc = kwSandboxInit(&g_Sandbox, pTool, cArgs, papszArgs, fWatcomBrainDamange, cEnvVars, papszEnvVars); 4427 4467 if (rc == 0) 4428 4468 { … … 4531 4571 * @param cArgs The number of arguments. 4532 4572 * @param papszArgs The argument vector. 4533 * @param cbArgs The size of the argument strings and terminators.4573 * @param fWatcomBrainDamange Whether to apply watcom rules while quoting. 4534 4574 * @param cEnvVars The number of environment variables. 4535 4575 * @param papszEnvVars The enviornment vector. 4536 4576 */ 4537 4577 static int kSubmitHandleJobUnpacked(const char *pszExecutable, const char *pszCwd, 4538 KU32 cArgs, const char **papszArgs, K U32 cbArgs,4578 KU32 cArgs, const char **papszArgs, KBOOL fWatcomBrainDamange, 4539 4579 KU32 cEnvVars, const char **papszEnvVars) 4540 4580 { … … 4580 4620 { 4581 4621 KW_LOG(("Sandboxing tool %s\n", pTool->pszPath)); 4582 rcExit = kwSandboxExec(pTool, cArgs, papszArgs, cbArgs, cEnvVars, papszEnvVars);4622 rcExit = kwSandboxExec(pTool, cArgs, papszArgs, fWatcomBrainDamange, cEnvVars, papszEnvVars); 4583 4623 } 4584 4624 else … … 4662 4702 if (papszArgs) 4663 4703 { 4664 KU32 cbArgs;4665 4704 KU32 i; 4666 4705 for (i = 0; i < cArgs; i++) … … 4679 4718 } 4680 4719 papszArgs[cArgs] = 0; 4681 cbArgs = (KU32)(pszMsg - papszArgs[0]) - cArgs + 1;4682 4720 4683 4721 /* Environment variable count. */ … … 4718 4756 if (cbMsg == 0) 4719 4757 { 4758 KBOOL fWatcomBrainDamange = K_FALSE; /** @todo fix fWatcomBrainDamange */ 4720 4759 /* 4721 4760 * The next step. 4722 4761 */ 4723 4762 rcExit = kSubmitHandleJobUnpacked(pszExecutable, pszCwd, 4724 cArgs, papszArgs, cbArgs,4763 cArgs, papszArgs, fWatcomBrainDamange, 4725 4764 cEnvVars, papszEnvVars); 4726 4765 } … … 4853 4892 char szCwd[MAX_PATH]; 4854 4893 const char *pszCwd = getcwd(szCwd, sizeof(szCwd)); 4855 KU32 cbArgs;4856 4894 KU32 cEnvVars; 4857 4895 … … 4898 4936 * Do the job. 4899 4937 */ 4900 cbArgs = 0;4901 for (j = i; j < argc; j++)4902 cbArgs += (KU32)strlen(argv[j]) + 1;4903 4904 4938 cEnvVars = 0; 4905 4939 while (environ[cEnvVars] != NULL) … … 4908 4942 for (j = 0; j < cRepeats; j++) 4909 4943 { 4910 rcExit = kSubmitHandleJobUnpacked(argv[i], pszCwd, argc - i, &argv[i], cbArgs, cEnvVars, environ); 4944 rcExit = kSubmitHandleJobUnpacked(argv[i], pszCwd, 4945 argc - i, &argv[i], K_FALSE /* fWatcomBrainDamange*/, 4946 cEnvVars, environ); 4911 4947 } 4912 4948
Note:
See TracChangeset
for help on using the changeset viewer.