mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-24 11:12:11 +01:00
GMappedFile: fail when mapping a device file
mmap() fails on zero-sized files, so we previously had a special case to avoid calling it in that case. Unfortunately, this had the side effect of causing us to fail to notice that we were attempting to mmap() a device node. Modify the special-casing to only apply in the case that we're dealing with a normal file. https://bugzilla.gnome.org/show_bug.cgi?id=659212
This commit is contained in:
parent
62ff5cd9f2
commit
817466f9a6
@ -173,7 +173,11 @@ g_mapped_file_new (const gchar *filename,
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (st.st_size == 0)
|
||||
/* mmap() on size 0 will fail with EINVAL, so we avoid calling mmap()
|
||||
* in that case -- but only if we have a regular file; we still want
|
||||
* attempts to mmap a character device to fail, for example.
|
||||
*/
|
||||
if (st.st_size == 0 && S_ISREG (st.st_mode))
|
||||
{
|
||||
file->length = 0;
|
||||
file->contents = NULL;
|
||||
|
@ -36,6 +36,18 @@ test_empty (void)
|
||||
g_mapped_file_free (file);
|
||||
}
|
||||
|
||||
static void
|
||||
test_device (void)
|
||||
{
|
||||
GError *error = NULL;
|
||||
GMappedFile *file;
|
||||
|
||||
file = g_mapped_file_new ("/dev/null", FALSE, &error);
|
||||
g_assert (file == NULL);
|
||||
g_assert (error != NULL);
|
||||
g_error_free (error);
|
||||
}
|
||||
|
||||
static void
|
||||
test_nonexisting (void)
|
||||
{
|
||||
@ -93,6 +105,7 @@ main (int argc, char *argv[])
|
||||
|
||||
g_test_add_func ("/mappedfile/basic", test_basic);
|
||||
g_test_add_func ("/mappedfile/empty", test_empty);
|
||||
g_test_add_func ("/mappedfile/device", test_device);
|
||||
g_test_add_func ("/mappedfile/nonexisting", test_nonexisting);
|
||||
g_test_add_func ("/mappedfile/writable", test_writable);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user