nvme: sanitize call to strerror()#3078
Open
martin-gpy wants to merge 2 commits intolinux-nvme:masterfrom
Open
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Avoid passing a negative int to strerror() for cleaner handling.