Package: libsoil1
Version: 1.07~20080707.dfsg-2
Severity: important
Tags: patch

libsoil crashes when executing most functions. The problem is that some
internal functions use glGetString improperly, glGetString then returns
a null pointer, and then those functions send that null pointer to
strstr, which causes a crash.

I have attached a patch which replaces glGetString with glGetIntegerv
and glGetStringi, which appears to be what was intended.

I also defined GL_GLEXT_PROTOTYPES before the call to include GL.h. It
alleviates many warnings, but I'm not sure if it affects the output or
if you'd rather do it a different way.

-Brandon
SOIL crashes when calling most functions. It calls glGetString with an invalid value, and then sends the returned null pointer to strstr. Fix that.
Index: libsoil-1.07~20080707.dfsg/src/SOIL.c
===================================================================
--- libsoil-1.07~20080707.dfsg.orig/src/SOIL.c	2013-10-22 18:58:45.254120080 -0700
+++ libsoil-1.07~20080707.dfsg/src/SOIL.c	2013-10-22 19:00:43.742117369 -0700
@@ -26,6 +26,7 @@
 	#include <Carbon/Carbon.h>
 	#define APIENTRY
 #else
+	#define GL_GLEXT_PROTOTYPES
 	#include <GL/gl.h>
 	#include <GL/glx.h>
 #endif
@@ -1870,16 +1871,25 @@
 	return tex_ID;
 }
 
+static int SOIL_internal_has_OGL_capability(const char * cap)
+{
+	int i;
+	GLint num_ext;
+	glGetIntegerv(GL_NUM_EXTENSIONS, &num_ext);
+	for (i = 0; i < num_ext; i++) {
+		if (!strcmp((const char *) glGetStringi(GL_EXTENSIONS, i), cap))
+			return GL_TRUE;
+	}
+	return GL_FALSE;
+}
+
 int query_NPOT_capability( void )
 {
 	/*	check for the capability	*/
 	if( has_NPOT_capability == SOIL_CAPABILITY_UNKNOWN )
 	{
 		/*	we haven't yet checked for the capability, do so	*/
-		if(
-			(NULL == strstr( (char const*)glGetString( GL_EXTENSIONS ),
-				"GL_ARB_texture_non_power_of_two" ) )
-			)
+		if( !SOIL_internal_has_OGL_capability( "GL_ARB_texture_non_power_of_two" ))
 		{
 			/*	not there, flag the failure	*/
 			has_NPOT_capability = SOIL_CAPABILITY_NONE;
@@ -1899,16 +1909,9 @@
 	if( has_tex_rectangle_capability == SOIL_CAPABILITY_UNKNOWN )
 	{
 		/*	we haven't yet checked for the capability, do so	*/
-		if(
-			(NULL == strstr( (char const*)glGetString( GL_EXTENSIONS ),
-				"GL_ARB_texture_rectangle" ) )
-		&&
-			(NULL == strstr( (char const*)glGetString( GL_EXTENSIONS ),
-				"GL_EXT_texture_rectangle" ) )
-		&&
-			(NULL == strstr( (char const*)glGetString( GL_EXTENSIONS ),
-				"GL_NV_texture_rectangle" ) )
-			)
+		if( !SOIL_internal_has_OGL_capability( "GL_ARB_texture_rectangle" ) &&
+		    !SOIL_internal_has_OGL_capability( "GL_EXT_texture_rectangle" ) &&
+		    !SOIL_internal_has_OGL_capability( "GL_NV_texture_rectangle" ) )
 		{
 			/*	not there, flag the failure	*/
 			has_tex_rectangle_capability = SOIL_CAPABILITY_NONE;
@@ -1928,13 +1931,8 @@
 	if( has_cubemap_capability == SOIL_CAPABILITY_UNKNOWN )
 	{
 		/*	we haven't yet checked for the capability, do so	*/
-		if(
-			(NULL == strstr( (char const*)glGetString( GL_EXTENSIONS ),
-				"GL_ARB_texture_cube_map" ) )
-		&&
-			(NULL == strstr( (char const*)glGetString( GL_EXTENSIONS ),
-				"GL_EXT_texture_cube_map" ) )
-			)
+		if( !SOIL_internal_has_OGL_capability( "GL_ARB_texture_cube_map" ) &&
+		    !SOIL_internal_has_OGL_capability( "GL_EXT_texture_cube_map" ) )
 		{
 			/*	not there, flag the failure	*/
 			has_cubemap_capability = SOIL_CAPABILITY_NONE;
@@ -1954,9 +1952,7 @@
 	if( has_DXT_capability == SOIL_CAPABILITY_UNKNOWN )
 	{
 		/*	we haven't yet checked for the capability, do so	*/
-		if( NULL == strstr(
-				(char const*)glGetString( GL_EXTENSIONS ),
-				"GL_EXT_texture_compression_s3tc" ) )
+		if( !SOIL_internal_has_OGL_capability( "GL_EXT_texture_compression_s3tc" ) )
 		{
 			/*	not there, flag the failure	*/
 			has_DXT_capability = SOIL_CAPABILITY_NONE;

Reply via email to