Skip to content

Commit

Permalink
v.out.ogr: Check for valid array before passing to qsort (OSGeo#4278)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
ymdatta authored and Mahesh1998 committed Sep 19, 2024
1 parent 0809ac8 commit f09e193
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion vector/v.out.ogr/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ char *OGR_list_write_drivers(void)
len += strlen(buf) + 1; /* + ',' */
}

qsort(list, count, sizeof(char *), cmp);
if (list)
qsort(list, count, sizeof(char *), cmp);

if (len > 0) {
ret = G_malloc((len + 1) * sizeof(char)); /* \0 */
Expand Down

0 comments on commit f09e193

Please sign in to comment.