diff --git a/src/ChangeLog b/src/ChangeLog index cbc54c078..ee22cd829 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2003-02-26 Pavel Roskin + + * view.c (load_view_file): Make sure view->s.st_size is not + truncated when passed to g_malloc(). + Reported by Philipp Thomas + 2003-02-23 Dmitry Alexeyev * key.c (get_modifier): Add support for QNX Neutrino console. diff --git a/src/view.c b/src/view.c index 477500228..168dfec71 100644 --- a/src/view.c +++ b/src/view.c @@ -585,13 +585,15 @@ load_view_file (WView *view, int fd) } #endif /* HAVE_MMAP */ - /* For those OS that dont provide mmap call. Try to load all the - * file into memory (alex@bcs.zaporizhzhe.ua). Also, mmap can fail + /* For the OSes that don't provide mmap call, try to load all the + * file into memory (alex@bcs.zaporizhzhe.ua). Also, mmap can fail * for any reason, so we use this as fallback (pavel@ucw.cz) */ - view->data = (unsigned char *) g_malloc (view->s.st_size); - if (view->data == NULL - || mc_lseek (view->file, 0, SEEK_SET) != 0 + /* Make sure view->s.st_size is not truncated when passed to g_malloc */ + if ((gulong) view->s.st_size == view->s.st_size) + view->data = (unsigned char *) g_malloc ((gulong) view->s.st_size); + + if (view->data == NULL || mc_lseek (view->file, 0, SEEK_SET) != 0 || mc_read (view->file, view->data, view->s.st_size) != view->s.st_size) { if (view->data != NULL)