AppJailLauncher icon indicating copy to clipboard operation
AppJailLauncher copied to clipboard

Subtle bug: checking against the wrong CreateJobObject return value

Open ariccio opened this issue 7 years ago • 0 comments

I'm screwing around with /analyze, and it's picked up a couple of issues for AppJailLauncher. Good software development on your part means this bug won't cause any bad behavior, but you might be confused if you're debugging.

At line 344 in utils.cpp you check the return value of CreateJobObject against INVALID_HANDLE_VALUE:

	hJob = CreateJobObject(NULL, NULL);
	W32_ASSERT(hJob != INVALID_HANDLE_VALUE, Exit);
	LOG("New job object created with handle %016p\n", hJob);

...but the docs say CreateJobObject returns NULL on failure:

If the function fails, the return value is NULL. To get extended error information, call GetLastError.

When CreateJobObject fails and you don't catch it here, it's not a big deal, because SetInformationJobObject should also fail. Because you properly check that return value, CreateLimitProcessTimeJobObject then returns E_FAIL, and the program exits with -1.

ariccio avatar Nov 30 '16 00:11 ariccio