Ensure file content is terminated (bug #1866212).

svn path=/trunk/netsurf/; revision=13070
This commit is contained in:
Steve Fryatt 2011-10-18 21:41:45 +00:00
parent 1dc36241d6
commit 67c9262403

View File

@ -4315,7 +4315,11 @@ bool ro_gui_window_import_text(struct gui_window *g, const char *filename,
return true; /* was for us, but it didn't work! */
}
buf = malloc(size);
/* Allocate one byte more than needed to ensure that the buffer is
* always terminated, regardless of file contents.
*/
buf = calloc(size + 1, sizeof(char));
if (!buf) {
warn_user("NoMemory", NULL);
return true;
@ -4323,6 +4327,7 @@ bool ro_gui_window_import_text(struct gui_window *g, const char *filename,
error = xosfile_load_stamped(filename, (byte*)buf,
NULL, NULL, NULL, NULL, NULL);
if (error) {
LOG(("xosfile_load_stamped: 0x%x:%s",
error->errnum, error->errmess));