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.external: Check for valid list before passing to qsort #4280

Merged
merged 1 commit into from
Sep 9, 2024

Conversation

ymdatta
Copy link
Contributor

@ymdatta ymdatta commented Sep 5, 2024

Currently, if 'HAVE_OGR' macro is defined, as part of execution, we order all formats by name using qsort. But, list containing all formats is assigned based on a conditional and if the conditional fails, it can be NULL.

Behavior of qsort is undefined when a NULL ptr is passed as array argument. To avoid getting into that 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. Should only be valid, when 'HAVE_OGR' flag is specified as part of the compilation process.
  4. Output from cppcheck prior to fix:
image

After the fix:

image

Currently, if 'HAVE_OGR' macro is defined, as part of execution,
we order all formats by name using qsort. But, list containing
all formats is assigned based on a conditional and if the
conditional fails, it can be NULL.

Behavior of qsort is undefined when a NULL ptr is passed as array
argument. To avoid getting into that 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 added this to the 8.5.0 milestone Sep 9, 2024
@petrasovaa petrasovaa merged commit 7c6c12b into OSGeo:main Sep 9, 2024
26 checks passed
This pull request was closed.
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.

3 participants