changeset 20915:65c27d3383ea

Prevent invalid data length from getting passed to fwrite.
author Daniel Atallah <daniel.atallah@gmail.com>
date Sat, 13 Oct 2007 16:55:57 +0000
parents 74ec24deb267
children e1f1f3c1c19c
files libpurple/util.c
diffstat 1 files changed, 3 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/util.c	Sat Oct 13 16:36:06 2007 +0000
+++ b/libpurple/util.c	Sat Oct 13 16:55:57 2007 +0000
@@ -2565,6 +2565,8 @@
 	purple_debug_info("util", "Writing file %s\n",
 					filename_full);
 
+	g_return_val_if_fail((size >= 0 || size == -1), FALSE);
+
 	filename_temp = g_strdup_printf("%s.save", filename_full);
 
 	/* Remove an old temporary file, if one exists */
@@ -2590,7 +2592,7 @@
 	}
 
 	/* Write to file */
-	real_size = (size == -1) ? strlen(data) : size;
+	real_size = (size == -1) ? strlen(data) : (size_t) size;
 	byteswritten = fwrite(data, 1, real_size, file);
 
 	/* Close file */