-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SDL: Fix buffer overflow in SDL_LoadFunction()
- Loading branch information
Showing
2 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Origin: https://github.com/libsdl-org/SDL-1.2/commit/447ec3d2c360902aa648bec44b612a040248871e | ||
From: Ozkan Sezer <sezeroz@gmail.com> | ||
Description: loadso, dlsym, SDL_LoadFunction: cleanup the underscored name path. | ||
- strlcpy was passed a wrong buffer length parameter. has worked so | ||
far by luck. | ||
- use memcpy instead of strlcpy for simplicity. | ||
- 'append' has been a typo: should be 'prepend'. | ||
diff --git a/src/loadso/dlopen/SDL_sysloadso.c b/src/loadso/dlopen/SDL_sysloadso.c | ||
index 7985ee7f9..56331a1f0 100644 | ||
--- a/src/loadso/dlopen/SDL_sysloadso.c | ||
+++ b/src/loadso/dlopen/SDL_sysloadso.c | ||
@@ -45,11 +45,11 @@ void *SDL_LoadFunction(void *handle, const char *name) | ||
{ | ||
void *symbol = dlsym(handle, name); | ||
if ( symbol == NULL ) { | ||
- /* append an underscore for platforms that need that. */ | ||
- size_t len = 1+SDL_strlen(name)+1; | ||
- char *_name = SDL_stack_alloc(char, len); | ||
+ /* prepend an underscore for platforms that need that. */ | ||
+ size_t len = SDL_strlen(name)+1; | ||
+ char *_name = SDL_stack_alloc(char, len+1); | ||
_name[0] = '_'; | ||
- SDL_strlcpy(&_name[1], name, len); | ||
+ SDL_memcpy(&_name[1], name, len); | ||
symbol = dlsym(handle, _name); | ||
SDL_stack_free(_name); | ||
if ( symbol == NULL ) { |