Tags: patch In Ubuntu, we've applied the attached patch to achieve the following:
- debian/patches/11-loadpng.patch: Fix FTBFS caused by ignoring the return value of some functions: + src/init.c: check the return code of realpath. + src/loadpng.c: handle short reads. We thought you might be interested in doing the same.
From: Artur Rona <ari-tc...@ubuntu.com> Description: Fix build errors caused by ignoring the return value of some functions. - src/init.c: check the return code of realpath. - src/loadpng.c: handle short reads. Bug-Debian: http://bugs.debian.org/511922 Origin: http://launchpadlibrarian.net/21243066/xbubble_0.5.11.2-2_0.5.11.2-2ubuntu1.diff.gz Author: James Westby <james.wes...@canonical.com> diff -pruN 0.5.11.2-3/src/init.c 0.5.11.2-3ubuntu2/src/init.c --- 0.5.11.2-3/src/init.c 2005-04-27 16:42:19.000000000 +0100 +++ 0.5.11.2-3ubuntu2/src/init.c 2010-03-08 22:38:42.000000000 +0000 @@ -97,7 +97,8 @@ static char * data_file( const char * fi path_max = 4096; #endif abs_data_dir = (char *) xmalloc( path_max * sizeof(char)); - realpath( data_dir, abs_data_dir ); + if (!realpath( data_dir, abs_data_dir )) + return NULL; offset = strlen(abs_data_dir); if ( offset > 1024-128 ) offset = 1024-128; @@ -119,8 +120,9 @@ static char * data_file( const char * fi } -static void load_levels( const char * file ) { +static void load_levels( const char * file_path ) { FILE *fd; + char * file; char line[128]; unsigned char r[8]; int i, cell = 0; @@ -129,7 +131,11 @@ static void load_levels( const char * fi int color, parse_error = 0; nb_levels = 0; - file = data_file(file, 0); + file = data_file(file_path, 0); + if ( file == NULL ) { + warn( _("cannot open levels file %s."), file_path); + return; + } fd = fopen( file, "r" ); if ( fd == NULL ) { @@ -232,6 +238,7 @@ static void add_font_path( char * path ) static XFontStruct * load_font( int pixel_size ) { XFontStruct * xfont; + char * font_path; char name[128]; int i; static int added_font_path = 0; @@ -245,7 +252,10 @@ static XFontStruct * load_font( int pixe } /* let's see if we can supply a font */ if ( ! added_font_path ) { - add_font_path(data_file("",0)); + font_path = data_file("", 0); + if ( font_path == NULL ) + fail( _("couldn't determine path to load font !") ); + add_font_path(font_path); added_font_path = 1; } sprintf( name, SUPPLIED_FONT, pixel_size ); @@ -276,8 +286,13 @@ static Frame load_frame( char *file, dou RgbaImage ri1; RgbaImage ri2; Frame frame = (Frame) xmalloc( sizeof( struct _Frame )); + char * png_file; - ri1 = create_rgba_image_from_png_file(data_file(file,1)); + png_file = data_file(file, 1); + if ( png_file == NULL ) { + fail(_("Couldn't get file to load frame from")); + } + ri1 = create_rgba_image_from_png_file(png_file); /* ri2 = ( zoom < 1.0 )? scale_rgba_image( ri1, zoom, zoom ) : ri1; */ ri2 = scale_rgba_image( ri1, zoom, zoom ) ; pmask = ( ri2->has_alpha )? &mask : NULL; @@ -322,11 +337,16 @@ static Set load_animation( const char *f char line[128]; char framename[128]; FILE *fd; + char * animation_file; /* open animation description file */ - fd = fopen( data_file(filename,1), "r" ); + animation_file = data_file(filename,1); + if ( animation_file == NULL ) { + fail(_("couldn't get file to load animation from")); + } + fd = fopen( animation_file, "r" ); if ( fd == NULL ) - fail( _("cannot open animation file %s."), data_file(filename,1) ); + fail( _("cannot open animation file %s."), animation_file ); /* count frames */ while ( fgets( line, 128, fd ) != NULL ) { @@ -362,7 +382,13 @@ static Set load_animation( const char *f static void load_scaled_image( const char *file, Pixmap *pix, Pixmap *mask, double zoom ) { RgbaImage ri1; RgbaImage ri2; - ri1 = create_rgba_image_from_png_file(data_file(file,1)); + char * png_file; + + png_file = data_file(file, 1); + if ( png_file == NULL ) { + fail(_("Couldn't load file to scale image")); + } + ri1 = create_rgba_image_from_png_file(png_file); ri2 = ( zoom < 1.0 )? scale_rgba_image( ri1, zoom, zoom ) : ri1; create_pixmaps_from_rgba_image( ri2, pix, mask ); delete_rgba_image(ri1); @@ -390,8 +416,13 @@ static void make_canon_animation( double Pixmap mask; Frame frame; int i; + char * canon_data_file; - ri2 = create_rgba_image_from_png_file(data_file("canon.png",1)); + canon_data_file = data_file("canon.png",1); + if ( canon_data_file == NULL ) { + fail(_("Couldn't load file for canon information")); + } + ri2 = create_rgba_image_from_png_file(canon_data_file); ri2->hotx = CANON_CX; ri2->hoty = CANON_CY; ri = scale_rgba_image( ri2, zoom, zoom ); @@ -503,6 +534,9 @@ static void load_animations( double zoom /* bubble animation */ dir = data_file("./",1); + if ( dir == NULL ) { + fail(_("couldn't get dir for loading bubble")); + } n = scandir(dir, &namelist, diren_select_bubbles , alphasort); if (n < 0) fail(_("Error while scanning %s"),dir); @@ -747,6 +781,7 @@ void splash_screen( double zoom ) { char * subtitle = _("Loading graphics ..."); const char *config_file = "config.txt"; + char * config_data_file; FILE *fd = NULL ; char line[128]; char *copy = NULL; @@ -759,7 +794,11 @@ void splash_screen( double zoom ) { double newzoom = zoom; int i; - fd = fopen( data_file(config_file,1), "r" ); + config_data_file = data_file(config_file,1); + if ( config_data_file == NULL ) { + fail(_("Couldn't find data file for splash screen")); + } + fd = fopen( config_data_file, "r" ); if(fd) { /* time to change default values... */ while ( fgets( line, 128, fd ) != NULL ) { lc++; diff -pruN 0.5.11.2-3/src/loadpng.c 0.5.11.2-3ubuntu2/src/loadpng.c --- 0.5.11.2-3/src/loadpng.c 2005-04-22 17:13:04.000000000 +0100 +++ 0.5.11.2-3ubuntu2/src/loadpng.c 2010-03-08 22:38:42.000000000 +0000 @@ -18,6 +18,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include <errno.h> #include <stdio.h> #include <stdlib.h> #include <png.h> @@ -43,7 +44,8 @@ unsigned char * load_png_file( const cha FILE *fd; unsigned char *data; unsigned char header[8]; - int bit_depth, color_type, i; + unsigned char *header_ptr; + int bit_depth, color_type, i, bytes_to_read, bytes_read; png_uint_32 png_width, png_height, rowbytes; png_structp png_ptr; png_infop info_ptr; @@ -55,7 +57,22 @@ unsigned char * load_png_file( const cha return NULL; } /* ensure that we opened a PNG file */ - fread( header, 1, 8, fd ); + bytes_to_read = 8; + header_ptr = header; + do { + bytes_read = fread( header_ptr, 1, bytes_to_read, fd ); + if (bytes_read == bytes_to_read) + break; + if (bytes_read >= 0) { + bytes_to_read -= bytes_read; + header_ptr += bytes_read; + } + } while (bytes_read >= 0 || errno == EINTR); + if (bytes_read == 0) { + fclose(fd); + fprintf(stderr,_("Error reading from %s.\n"), file); + return NULL; + } if ( ! png_check_sig( header, 8 ) ) { fclose(fd); fprintf(stderr,_("File %s does not have a valid PNG signature.\n"), file);