Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v.out.ogr: Check for valid array before passing to qsort #4278

Merged
merged 1 commit into from
Sep 9, 2024

Conversation

ymdatta
Copy link
Contributor

@ymdatta ymdatta commented Sep 5, 2024

Currently, filling list with GDAL driver names is based on a conditional and if the conditional fails, the list can be NULL.

We pass this list to qsort to sort the names, but behavior of qsort with a NULL array is undefined. To avoid getting into this situation, check if the array is NULL before performing qsort on it.

This issue was found using cppcheck tool.

Additional information:

  1. Machine used: Virtual Machine running Ubuntu 22.04.4 LTS.
  2. Reproduction rate: 100%, reproducible every time.
  3. Output from cppcheck prior to fix
image

After the fix

image

Currently, filling list with GDAL driver names is based on
a conditional and if the conditional fails, the list can be NULL.

We pass this list to qsort to sort the names, but behavior
of qsort with a NULL array is undefined. To avoid getting into this
situation, check if the array is NULL before performing qsort on it.

This issue was found using cppcheck tool.

Signed-off-by: Mohan Yelugoti <ymdatta.work@gmail.com>
@github-actions github-actions bot added vector Related to vector data processing C Related code is in C module labels Sep 5, 2024
@nilason nilason self-assigned this Sep 5, 2024
@nilason nilason added this to the 8.5.0 milestone Sep 5, 2024
@echoix
Copy link
Member

echoix commented Sep 9, 2024

Same pattern as #4251 and #4280

@echoix echoix merged commit 85efe79 into OSGeo:main Sep 9, 2024
26 checks passed
Mahesh1998 pushed a commit to Mahesh1998/grass that referenced this pull request Sep 19, 2024
Currently, filling list with GDAL driver names is based on
a conditional and if the conditional fails, the list can be NULL.

We pass this list to qsort to sort the names, but behavior
of qsort with a NULL array is undefined. To avoid getting into this
situation, check if the array is NULL before performing qsort on it.

This issue was found using cppcheck tool.

Signed-off-by: Mohan Yelugoti <ymdatta.work@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C Related code is in C module vector Related to vector data processing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants