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.out: Check for valid array before passing it to qsort #4251

Merged
merged 1 commit into from
Aug 30, 2024

Conversation

ymdatta
Copy link
Contributor

@ymdatta ymdatta commented Aug 29, 2024

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

Behavior of qsort when a NULL array is provided is undefined. To avoid getting into that situation, check if the array is NULL before performing qsort on it.

This issue was found by 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 sort all formats by name using qsort. But, array containing
all formats is assigned based on a conditional and if the
conditional fails, it can be NULL.

Behavior of qsort when a NULL array is provided is undefined.
To avoid getting into that situation, check if the array is
NULL before performing qsort on it.

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 Aug 29, 2024
@wenzeslaus wenzeslaus changed the title v.external.out: check for valid array before passing it to qsort v.external.out: Check for valid array before passing it to qsort Aug 30, 2024
@wenzeslaus wenzeslaus merged commit cdb6282 into OSGeo:main Aug 30, 2024
27 checks passed
@neteler neteler added this to the 8.5.0 milestone Aug 30, 2024
a0x8o pushed a commit to a0x8o/grass that referenced this pull request Sep 5, 2024
…eo#4251)

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

Behavior of qsort when a NULL array is provided is undefined. To avoid getting into that situation, check if the array is NULL before performing qsort on it.

Signed-off-by: Mohan Yelugoti <ymdatta.work@gmail.com>
Mahesh1998 pushed a commit to Mahesh1998/grass that referenced this pull request Sep 19, 2024
…eo#4251)

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

Behavior of qsort when a NULL array is provided is undefined. To avoid getting into that situation, check if the array is NULL before performing qsort on it.

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.

3 participants