Bug: Wrong/missing return value check of mmap function in lsm_unix.c
(1) By trisbauer on 2020-06-22 14:25:25 [link]
There is a wrong/missing return value check of the mmap function in the file lsm_unix.c. The return value is checked against 0, but mmap returns MAP_FAILED (-1) on errors. I created a pull request with a fix on the sqlcipher GitHub page but I was asked to forward this request to the SQLite team: https://github.com/sqlcipher/sqlcipher/pull/364
(2.1) By Stephan Beal (stephan) on 2020-06-22 15:32:59 edited from 2.0 in reply to 1 [link]
> There is a wrong/missing return value check of the mmap function in the file lsm_unix.c. The return value is checked against 0, but mmap returns MAP_FAILED (-1) on errors. [`mmap()` returns a pointer][mmap], and 0 is equivalent to a `NULL` pointer. Edit: nevermind. the man page clearly says that it returns a `(void*)-1`... which is weird, but okay. Sorry for the noise. [mmap]: https://man7.org/linux/man-pages/man2/mmap.2.html
(3) By Dan Kennedy (dan) on 2020-06-22 16:03:04 in reply to 1
Thanks for reporting this. [](https://sqlite.org/src/info/da06168c09df5c0e)
(4) By trisbauer on 2020-06-22 20:15:21 in reply to 3 [link]
No problem. I found this a bug by using the following script: <https://github.com/hannob/mmapfail>