Getting segmentation fault SIGSEGV in memcpy after mmap

前端 未结 4 1804
既然无缘
既然无缘 2021-01-23 16:50

I wrote a simple Android native function that get a filename and some more arguments and read the file by mmapping (mmap) it\'s memory.

Because it\'s mmap, I don\'t real

4条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-23 17:15

    The while loop is infinite:

    while(ret_val == buffer || read_length

    as memcpy() always returns the desintation buffer so ret_val == buffer will always be true (and is therefore useless as part of the terminating condition). This means that addr is being incremented by jbuffer_size bytes on every iteration of the loop and is passed to memcpy(), resuting in accessing invalid memory.

提交回复
热议问题