From 67c9262403635a1689401d690a6bbf0fd95fb1d7 Mon Sep 17 00:00:00 2001 From: Steve Fryatt Date: Tue, 18 Oct 2011 21:41:45 +0000 Subject: Ensure file content is terminated (bug #1866212). svn path=/trunk/netsurf/; revision=13070 --- riscos/window.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'riscos/window.c') diff --git a/riscos/window.c b/riscos/window.c index de3617db4..6defacf36 100644 --- a/riscos/window.c +++ b/riscos/window.c @@ -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)); -- cgit v1.2.3