Skip to content

nvme: sanitize call to strerror()#3078

Open
martin-gpy wants to merge 2 commits intolinux-nvme:masterfrom
martin-gpy:sanitize_strerror
Open

nvme: sanitize call to strerror()#3078
martin-gpy wants to merge 2 commits intolinux-nvme:masterfrom
martin-gpy:sanitize_strerror

Conversation

@martin-gpy
Copy link
Contributor

Avoid passing a negative int to strerror() for cleaner handling.

Valgrind revealed a mem leak while running nvme list-subsys -vv:

==2486== 18 bytes in 1 blocks are still reachable in loss record 1 of 1
==2486==    at 0x4841984: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==2486==    by 0x4956037: __vasprintf_internal (in /lib64/libc.so.6)
==2486==    by 0x49F73AE: __asprintf_chk (in /lib64/libc.so.6)
==2486==    by 0x49796FB: strerror_l (in /lib64/libc.so.6)
==2486==    by 0x488A4AF: nvme_scan_topology (tree.c:317)
==2486==    by 0x42E3BC: list_subsys (nvme.c:3499)
==2486==    by 0x445F88: handle_plugin (plugin.c:190)
==2486==    by 0x407620: main (nvme.c:11119)

Fix this by ensuring an appropriate value is passed to strerror().

Signed-off-by: Martin George <marting@netapp.com>
Passing a negative int to strerror() may lead to undefined behavior
and also result in a mem leak. Fix this by ensuring an appropriate
value is passed instead.

Signed-off-by: Martin George <marting@netapp.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant