SDL_image shouldn't dereference a rwops if it's NULL.
authorRyan C. Gordon <icculus@icculus.org>
Tue, 13 Feb 2007 10:09:17 +0000
changeset 154201cc5c1b373
parent 153 ebab84a66b57
child 155 b57382b1ebf5
SDL_image shouldn't dereference a rwops if it's NULL.

Fixes Bugzilla #284.
IMG_bmp.c
IMG_gif.c
IMG_jpg.c
IMG_lbm.c
IMG_pcx.c
IMG_png.c
IMG_pnm.c
IMG_tif.c
IMG_xcf.c
IMG_xpm.c
IMG_xv.c
IMG_xxx.c
     1.1 --- a/IMG_bmp.c	Tue Feb 13 10:00:29 2007 +0000
     1.2 +++ b/IMG_bmp.c	Tue Feb 13 10:09:17 2007 +0000
     1.3 @@ -36,6 +36,8 @@
     1.4  	int is_BMP;
     1.5  	char magic[2];
     1.6  
     1.7 +	if ( !src )
     1.8 +		return 0;
     1.9  	start = SDL_RWtell(src);
    1.10  	is_BMP = 0;
    1.11  	if ( SDL_RWread(src, magic, sizeof(magic), 1) ) {
     2.1 --- a/IMG_gif.c	Tue Feb 13 10:00:29 2007 +0000
     2.2 +++ b/IMG_gif.c	Tue Feb 13 10:09:17 2007 +0000
     2.3 @@ -36,6 +36,8 @@
     2.4  	int is_GIF;
     2.5  	char magic[6];
     2.6  
     2.7 +	if ( !src )
     2.8 +		return 0;
     2.9  	start = SDL_RWtell(src);
    2.10  	is_GIF = 0;
    2.11  	if ( SDL_RWread(src, magic, sizeof(magic), 1) ) {
     3.1 --- a/IMG_jpg.c	Tue Feb 13 10:00:29 2007 +0000
     3.2 +++ b/IMG_jpg.c	Tue Feb 13 10:09:17 2007 +0000
     3.3 @@ -179,6 +179,8 @@
     3.4  	/* Blame me, not Sam, if this doesn't work right. */
     3.5  	/* And don't forget to report the problem to the the sdl list too! */
     3.6  
     3.7 +	if ( !src )
     3.8 +		return 0;
     3.9  	start = SDL_RWtell(src);
    3.10  	is_JPG = 0;
    3.11  	in_scan = 0;
     4.1 --- a/IMG_lbm.c	Tue Feb 13 10:00:29 2007 +0000
     4.2 +++ b/IMG_lbm.c	Tue Feb 13 10:09:17 2007 +0000
     4.3 @@ -65,6 +65,8 @@
     4.4  	int   is_LBM;
     4.5  	Uint8 magic[4+4+4];
     4.6  
     4.7 +	if ( !src ) 
     4.8 +		return 0;
     4.9  	start = SDL_RWtell(src);
    4.10  	is_LBM = 0;
    4.11  	if ( SDL_RWread( src, magic, sizeof(magic), 1 ) )
     5.1 --- a/IMG_pcx.c	Tue Feb 13 10:00:29 2007 +0000
     5.2 +++ b/IMG_pcx.c	Tue Feb 13 10:09:17 2007 +0000
     5.3 @@ -69,6 +69,8 @@
     5.4  	const int PCX_RunLength_Encoding = 1;
     5.5  	struct PCXheader pcxh;
     5.6  
     5.7 +	if ( !src )
     5.8 +		return 0;
     5.9  	start = SDL_RWtell(src);
    5.10  	is_PCX = 0;
    5.11  	if ( SDL_RWread(src, &pcxh, sizeof(pcxh), 1) == 1 ) {
     6.1 --- a/IMG_png.c	Tue Feb 13 10:00:29 2007 +0000
     6.2 +++ b/IMG_png.c	Tue Feb 13 10:09:17 2007 +0000
     6.3 @@ -273,6 +273,8 @@
     6.4  	if ( IMG_InitPNG() < 0 ) {
     6.5  		return 0;
     6.6  	}
     6.7 +	if ( !src )
     6.8 +		return 0;
     6.9  	start = SDL_RWtell(src);
    6.10  	is_PNG = 0;
    6.11  	if ( SDL_RWread(src, buf, 1, PNG_BYTES_TO_CHECK) == PNG_BYTES_TO_CHECK ) {
     7.1 --- a/IMG_pnm.c	Tue Feb 13 10:00:29 2007 +0000
     7.2 +++ b/IMG_pnm.c	Tue Feb 13 10:09:17 2007 +0000
     7.3 @@ -44,6 +44,8 @@
     7.4  	int is_PNM;
     7.5  	char magic[2];
     7.6  
     7.7 +	if ( !src )
     7.8 +		return 0;
     7.9  	start = SDL_RWtell(src);
    7.10  	is_PNM = 0;
    7.11  	if ( SDL_RWread(src, magic, sizeof(magic), 1) ) {
     8.1 --- a/IMG_tif.c	Tue Feb 13 10:00:29 2007 +0000
     8.2 +++ b/IMG_tif.c	Tue Feb 13 10:09:17 2007 +0000
     8.3 @@ -174,6 +174,8 @@
     8.4  	if ( IMG_InitTIF() < 0 ) {
     8.5  		return 0;
     8.6  	}
     8.7 +	if ( !src )
     8.8 +		return 0;
     8.9  	start = SDL_RWtell(src);
    8.10  	is_TIF = 0;
    8.11  
     9.1 --- a/IMG_xcf.c	Tue Feb 13 10:00:29 2007 +0000
     9.2 +++ b/IMG_xcf.c	Tue Feb 13 10:09:17 2007 +0000
     9.3 @@ -213,6 +213,8 @@
     9.4  	int is_XCF;
     9.5  	char magic[14];
     9.6  
     9.7 +	if ( !src )
     9.8 +		return 0;
     9.9  	start = SDL_RWtell(src);
    9.10  	is_XCF = 0;
    9.11  	if ( SDL_RWread(src, magic, sizeof(magic), 1) ) {
    10.1 --- a/IMG_xpm.c	Tue Feb 13 10:00:29 2007 +0000
    10.2 +++ b/IMG_xpm.c	Tue Feb 13 10:09:17 2007 +0000
    10.3 @@ -59,6 +59,8 @@
    10.4  	int is_XPM;
    10.5  	char magic[9];
    10.6  
    10.7 +	if ( !src )
    10.8 +		return 0;
    10.9  	start = SDL_RWtell(src);
   10.10  	is_XPM = 0;
   10.11  	if ( SDL_RWread(src, magic, sizeof(magic), 1) ) {
   10.12 @@ -326,7 +328,8 @@
   10.13  	linebuf = NULL;
   10.14  	buflen = 0;
   10.15  
   10.16 -	start = SDL_RWtell(src);
   10.17 +	if ( src ) 
   10.18 +		start = SDL_RWtell(src);
   10.19  
   10.20  	if(xpm)
   10.21  		xpmlines = &xpm;
   10.22 @@ -453,7 +456,8 @@
   10.23  
   10.24  done:
   10.25  	if(error) {
   10.26 -		SDL_RWseek(src, start, SEEK_SET);
   10.27 +		if ( src )
   10.28 +			SDL_RWseek(src, start, SEEK_SET);
   10.29  		if ( image ) {
   10.30  			SDL_FreeSurface(image);
   10.31  			image = NULL;
    11.1 --- a/IMG_xv.c	Tue Feb 13 10:00:29 2007 +0000
    11.2 +++ b/IMG_xv.c	Tue Feb 13 10:09:17 2007 +0000
    11.3 @@ -89,6 +89,8 @@
    11.4  	int is_XV;
    11.5  	int w, h;
    11.6  
    11.7 +	if ( !src )
    11.8 +		return 0;
    11.9  	start = SDL_RWtell(src);
   11.10  	is_XV = 0;
   11.11  	if ( get_header(src, &w, &h) == 0 ) {
    12.1 --- a/IMG_xxx.c	Tue Feb 13 10:00:29 2007 +0000
    12.2 +++ b/IMG_xxx.c	Tue Feb 13 10:09:17 2007 +0000
    12.3 @@ -34,6 +34,8 @@
    12.4  	int start;
    12.5  	int is_XXX;
    12.6  
    12.7 +	if ( !src )
    12.8 +		return 0;
    12.9  	start = SDL_RWtell(src);
   12.10  	is_XXX = 0;
   12.11