GNOME Bugzilla – Bug 659212
GMappedFile should fail on non-regular files
Last modified: 2011-09-18 00:03:37 UTC
Currently it returns an empty file because fstat() returns 0 filesize and we return early. Correct fix should return an error. Ideally an error that can be detected such that the caller can revert back to fread()ing. While discussing this, we figured that the documentation for G_FILE_ERROR_NODEV is also inadequate.
Created attachment 196687 [details] [review] 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.
Review of attachment 196687 [details] [review]: Looks good to me
I still appreciate a documented error code that lets the caller decide to try g_file_get_contents() instead.
The following fixes have been pushed: f18eab2 GMappedFile: return an error when trying to map a device 500202a GMappedFile: return an error when trying to map a device 817466f GMappedFile: fail when mapping a device file
Created attachment 196853 [details] [review] GMappedFile: return an error when trying to map a device Previously, we were returning an empty buffer for all filenames where fstat() gives a size of 0. But this is only appropriate for regular files. Also improve the documentation around this issue. Based on a patch by Ryan Lortie. Conflicts: glib/tests/mappedfile.c
Created attachment 196854 [details] [review] GMappedFile: return an error when trying to map a device Previously, we were returning an empty buffer for all filenames where fstat() gives a size of 0. But this is only appropriate for regular files. Also improve the documentation around this issue. Based on a patch by Ryan Lortie.
Created attachment 196855 [details] [review] 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.