[Libburn] [PATCH] libisofs test segfaults

Joe Neeman neeman at webone.com.au
Sun Jul 31 21:20:12 EST 2005


Thanks for the patch; I've modified it so that it prints a warning 
message in iso_tree_radd_dir(). I have also added some things to the patch:
 - removed assertions relating to the return value of stat(); it's 
better to test the value and return NULL
 - prevented the writer from failing if it can't open a file: fill it 
with zeros instead

I'm pretty sure these (tree.c and the file writer) are the only areas in 
which input to libisofs actually occurs, so these should be the only 
possible points of failure.

Joe
-------------- next part --------------
Index: libisofs/tree.c
===================================================================
--- libisofs/tree.c	(revision 20)
+++ libisofs/tree.c	(working copy)
@@ -9,6 +9,7 @@
 #include <sys/types.h>
 #include <time.h>
 #include <assert.h>
+#include <errno.h>
 
 #include "libisofs.h"
 #include "tree.h"
@@ -104,7 +105,11 @@
 
 	assert( parent != NULL && path != NULL );
 	statret = lstat(path, &st);
-	assert( statret != -1 && !S_ISDIR(st.st_mode) );
+	if (statret == -1) {
+		fprintf(stderr, "couldn't stat file %s: %s\n",
+				path, strerror(errno));
+		return NULL;
+	}
 
 	/* Set up path, parent and volume. */
 	file = calloc(1, sizeof(struct iso_tree_file));
@@ -145,7 +150,11 @@
 
 	assert( parent && path );
 	statret = stat(path, &st);
-	assert( statret != -1 && S_ISDIR(st.st_mode) );
+	if (statret == -1) {
+		fprintf(stderr, "couldn't stat directory %s: %s\n",
+				path, strerror(errno));
+		return NULL;
+	}
 
 	dir = calloc(1, sizeof(struct iso_tree_dir));
 	dir->parent = parent;
@@ -189,13 +198,19 @@
 
 	assert( parent && path );
 	statret = stat(path, &st);
-	assert( statret != -1 && S_ISDIR(st.st_mode) );
 
 	nparent = iso_tree_add_dir(parent, path);
 
 	/* Open the directory for reading and iterate over the directory
 	   entries. */
 	dir = opendir(path);
+
+	if (!dir) {
+		fprintf(stderr, "couldn't open directory %s: %s\n",
+				path, strerror(errno));
+		return NULL;
+	}
+
 	while ((ent = readdir(dir))) {
 		char *child;
 
Index: libisofs/ecma119.c
===================================================================
--- libisofs/ecma119.c	(revision 21)
+++ libisofs/ecma119.c	(working copy)
@@ -1195,11 +1195,14 @@
 		if (!SDATA.fd) {
 			fprintf(stderr, "Error: couldn't open file %s: %s\n",
 					f->path, strerror(errno));
-			return;
 		}
 	}
 
-	numread = fread(buf, 1, 2048, SDATA.fd);
+	if (SDATA.fd) {
+		numread = fread(buf, 1, 2048, SDATA.fd);
+	} else {
+		numread = t->block_size;
+	}
 	if (numread == -1) {
 		fprintf(stderr, "Error reading file: %s\n", strerror(errno));
 		return;
Index: libisofs/test.c
===================================================================
--- libisofs/test.c	(revision 20)
+++ libisofs/test.c	(working copy)
@@ -86,13 +86,16 @@
 		return 1;
 	}
 	fd = fopen(argv[optind+1], "w");
+	if (!fd) {
+		perror("error opening output file");
+		exit(1);
+	}
 
 	volume = iso_volume_new( "VOLID", "PUBID", "PREPID" );
 	volset = iso_volset_new( volume, "VOLSETID" );
 	dir = opendir(argv[optind]);
 	if (!dir) {
-		fprintf(stderr, "error: couldn't open directory %s: %s\n",
-				argv[optind], strerror(errno));
+		perror("error opening input directory");
 		exit(1);
 	}
 


More information about the libburn mailing list