Open
Conversation
Flatten control flow to use a single exit path. Fixes leaks, including
of dmi_fname and entry_fname. Reported by Coverity:
libsmbios-2.4.3/src/libsmbios_c/smbios/smbios_linux.c:104: alloc_arg: "asprintf" allocates memory that is stored into "dmi_fname". [Note: The source code implementation of the function has been overridden by a builtin model.]
libsmbios-2.4.3/src/libsmbios_c/smbios/smbios_linux.c:131: noescape: Resource "dmi_fname" is not freed or pointed-to in "read_file".
libsmbios-2.4.3/src/libsmbios_c/smbios/smbios_linux.c:160: leaked_storage: Variable "dmi_fname" going out of scope leaks the storage it points to.
# 158| free(entry_buffer);
# 159| fnprintf(" out: %d\n", retval);
# 160|-> return retval;
# 161| }
# 162|
libsmbios-2.4.3/src/libsmbios_c/smbios/smbios_linux.c:100: alloc_arg: "asprintf" allocates memory that is stored into "entry_fname". [Note: The source code implementation of the function has been overridden by a builtin model.]
libsmbios-2.4.3/src/libsmbios_c/smbios/smbios_linux.c:111: noescape: Resource "entry_fname" is not freed or pointed-to in "read_file".
libsmbios-2.4.3/src/libsmbios_c/smbios/smbios_linux.c:160: leaked_storage: Variable "entry_fname" going out of scope leaks the storage it points to.
# 158| free(entry_buffer);
# 159| fnprintf(" out: %d\n", retval);
# 160|-> return retval;
# 161| }
# 162|
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
Reported by Coverity:
libsmbios-2.4.3/src/libsmbios_c/smbios/smbios_obj.c:82: address: Taking address of "singleton".
libsmbios-2.4.3/src/libsmbios_c/smbios/smbios_obj.c:82: assign: Assigning: "toReturn" = "&singleton".
libsmbios-2.4.3/src/libsmbios_c/smbios/smbios_obj.c:103: incorrect_free: "init_smbios_struct" frees incorrect pointer "toReturn".
# 101| }
# 102|
# 103|-> ret = init_smbios_struct(toReturn);
# 104| if (ret)
# 105| goto out_init_fail;
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
In the failure case, toReturn has been freed already, so dereferencing it to write to a struct member (initialized) is not valid. Signed-off-by: Robbie Harwood <rharwood@redhat.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.
For the first, I've opted for a more invasive change to the function since the control was harder to reason about, but I could provide a more minimal fix to the problems reported if that would be preferred.
Static analyzer notes about the issues are in the commit messages, which I can also remove if that would be preferred.