We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 545 - joystick: potential NULL pointer dereference
Summary: joystick: potential NULL pointer dereference
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: joystick (show other bugs)
Version: 1.2.13
Hardware: All All
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-02-01 09:38 UTC by Patrice Mandin
Modified: 2008-07-19 04:55 UTC (History)
0 users

See Also:


Attachments
There's no reason to analyze what the NULL-pointer is pointing to, so we want to return. (492 bytes, patch)
2008-07-07 09:54 UTC, Trygve Vea
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Patrice Mandin 2008-02-01 09:38:00 UTC
Around lines 140-150 in src/joystick/SDL_joystick.c:
--8<--
if ( ((joystick->naxes > 0) && !joystick->axes)
  || ((joystick->nhats > 0) && !joystick->hats)
  || ((joystick->nballs > 0) && !joystick->balls)
  || ((joystick->nbuttons > 0) && !joystick->buttons)) {
	SDL_OutOfMemory();
	SDL_JoystickClose(joystick);
	joystick = NULL;
}
if ( joystick->axes ) {
	SDL_memset(joystick->axes, 0,
		joystick->naxes*sizeof(Sint16));
}
--8<--

joystick variable is set to NULL, however, the checks that follow may still dereference it in this case.
Comment 1 Trygve Vea 2008-07-07 09:54:41 UTC
Created attachment 259 [details]
There's no reason to analyze what the NULL-pointer is pointing to, so we want to return.

I looked at the code, and as far as I can tell we should get a risk-free effect by returning immediatly instead of setting the pointer to NULL and continue the execution of the function.

Suggested patch attached.