Created attachment 180770 [details] git patch We have found and fixed a vulnerability using PVS-Studio tool. PVS-Studio is a static code analyzer for C, C++ and C#: https://www.viva64.com/en/pvs-studio/ Analyzer warning: V595 The 'mc' pointer was utilized before it was verified against nullptr. Check lines: 2954, 2955. mly.c 2954
Created attachment 185158 [details] mly.patch I would probably either move the check of mc_data into the 'if (mc != NULL)' block, or do the approach above where we just return immediately if we fail to get a command and then 'mc' is never NULL when 'out' is jumped to.
Your patch looks good to me. Will you commit it?
A commit references this bug: Author: jhb Date: Tue Aug 8 17:49:58 UTC 2017 New revision: 322270 URL: https://svnweb.freebsd.org/changeset/base/322270 Log: Fix a NULL pointer dereference in mly_user_command(). If mly_user_command fails to allocate a command slot it jumps to an 'out' label used for error handling. The error handling code checks for a data buffer in 'mc->mc_data' to free before checking if 'mc' is NULL. Fix by just returning directly if we fail to allocate a command and only using the 'out' label for subsequent errors when there is actual cleanup to perform. PR: 217747 Reported by: PVS-Studio Reviewed by: emaste MFC after: 1 week Changes: head/sys/dev/mly/mly.c
A commit references this bug: Author: jhb Date: Wed Sep 20 20:48:22 UTC 2017 New revision: 323826 URL: https://svnweb.freebsd.org/changeset/base/323826 Log: MFC 322270: Fix a NULL pointer dereference in mly_user_command(). If mly_user_command fails to allocate a command slot it jumps to an 'out' label used for error handling. The error handling code checks for a data buffer in 'mc->mc_data' to free before checking if 'mc' is NULL. Fix by just returning directly if we fail to allocate a command and only using the 'out' label for subsequent errors when there is actual cleanup to perform. PR: 217747 Reported by: PVS-Studio Changes: _U stable/10/ stable/10/sys/dev/mly/mly.c _U stable/11/ stable/11/sys/dev/mly/mly.c