g-udisks-volume: fix incorrect g_realloc and memcpy usage#124
Open
mtasaka wants to merge 1 commit into
Open
Conversation
gcc17 -fanalyzer warns: src/udisks/g-udisks-volume.c:302:45: warning: allocated buffer size is not a multiple of the pointee's size [CWE-131] [-Wanalyzer-allocation-size] Actually: 1. The second argument of g_realloc: "+2" is apparently wrong: it should be `len + 2`, also should be multiplied by the size of element. 2. The direction (in other words, the first and second arguments) of memcpy is swapped. The latter line seems to be trying to prepend `OUT_mount_path` to mount_paths, so mount_paths[0] should be moved to mount_paths[1] 3. `data->vol->dev->mount_paths + sizeof(char*)` points to the `sizeof(char*)`-th element of `mount_paths` (starting at 0), which is apparently not intended: which should be 1th element (starting at 0). 4. Using `memcpy` for overwrapping region is incorrect. That should be `memmove`. 5. `len` value, which is the result of `g_strv_length`, does not count the last NULL sentinel. So to count the size of `memmove`, the last NULL sentinel must be considered. This change fixes the above issues.
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.
gcc17 -fanalyzer warns:
src/udisks/g-udisks-volume.c:302:45: warning: allocated buffer size is not a multiple of the pointee's size [CWE-131] [-Wanalyzer-allocation-size]
Actually:
len + 2, also should be multiplied by the size of element.OUT_mount_pathto mount_paths, so mount_paths[0] should be moved to mount_paths[1]data->vol->dev->mount_paths + sizeof(char*)points to thesizeof(char*)-th element ofmount_paths(starting at 0), which is apparently not intended: which should be 1th element (starting at 0).memcpyfor overwrapping region is incorrect. That should bememmove.lenvalue, which is the result ofg_strv_length, does not count the last NULL sentinel. So to count the size ofmemmove, the last NULL sentinel must be considered.This change fixes the above issues.