From 38094ffb5cb824f91e86553c8925517d3cbb4356 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 5 Sep 2005 18:20:24 +0000 Subject: [PATCH] Report an error if the file is too large. (#315275, Kjartan Maraas) 2005-09-05 Matthias Clasen * glib/gmappedfile.c (g_mapped_file_new): Report an error if the file is too large. (#315275, Kjartan Maraas) --- ChangeLog | 3 +++ ChangeLog.pre-2-10 | 3 +++ ChangeLog.pre-2-12 | 3 +++ glib/gmappedfile.c | 15 +++++++++++---- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9d3cc77df..e1bc06beb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2005-09-05 Matthias Clasen + * glib/gmappedfile.c (g_mapped_file_new): Report an error + if the file is too large. (#315275, Kjartan Maraas) + * glib/gkeyfile.c (g_key_file_load_from_fd): The return value of read() is signed. (#315273, Kjartan Maraas) diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 9d3cc77df..e1bc06beb 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,5 +1,8 @@ 2005-09-05 Matthias Clasen + * glib/gmappedfile.c (g_mapped_file_new): Report an error + if the file is too large. (#315275, Kjartan Maraas) + * glib/gkeyfile.c (g_key_file_load_from_fd): The return value of read() is signed. (#315273, Kjartan Maraas) diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 9d3cc77df..e1bc06beb 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,5 +1,8 @@ 2005-09-05 Matthias Clasen + * glib/gmappedfile.c (g_mapped_file_new): Report an error + if the file is too large. (#315275, Kjartan Maraas) + * glib/gkeyfile.c (g_key_file_load_from_fd): The return value of read() is signed. (#315273, Kjartan Maraas) diff --git a/glib/gmappedfile.c b/glib/gmappedfile.c index 2321ee6b4..993535666 100644 --- a/glib/gmappedfile.c +++ b/glib/gmappedfile.c @@ -140,10 +140,17 @@ g_mapped_file_new (const gchar *filename, file->contents = MAP_FAILED; #ifdef HAVE_MMAP - file->length = st.st_size; - file->contents = (gchar *) mmap (NULL, st.st_size, - writable ? PROT_READ|PROT_WRITE : PROT_READ, - MAP_PRIVATE, fd, 0); + if (st.st_size > G_MAXSIZE) + { + errno = EINVAL; + } + else + { + file->length = (gsize) st.st_size; + file->contents = (gchar *) mmap (NULL, file->length, + writable ? PROT_READ|PROT_WRITE : PROT_READ, + MAP_PRIVATE, fd, 0); + } #endif #ifdef G_OS_WIN32 file->length = st.st_size;