Check the return value of fread() when loading SQL migration files.
authorMahlon E. Smith <mahlon@martini.nu>
Thu, 22 Sep 2011 21:43:25 -0700
changeset 5 7718f04c8cd1
parent 4 5701b7859a31
child 6 85718bc3ff47
Check the return value of fread() when loading SQL migration files.
util.c
--- a/util.c	Wed Sep 14 16:49:28 2011 -0700
+++ b/util.c	Thu Sep 22 21:43:25 2011 -0700
@@ -149,9 +149,13 @@
 		return( NULL );
 	}
 
-	fread( contents, sizeof(char), sb.st_size, fh );
+	if ( fread( contents, sizeof(char), sb.st_size, fh ) != sb.st_size ) {
+		debug( 1, LOC, "Short read for file '%s'?: %s\n", file );
+		fclose( fh );
+		return( NULL );
+	}
+
 	fclose( fh );
-
 	return( contents );
 }