Skip to content

Commit

Permalink
r.mask.status: fix null pointer dereference and false positive string…
Browse files Browse the repository at this point in the history
… overflow (#4512)

Fixes two new issues reported by Coverity Scan:

- Handles case of unsuccessful creation of json string
- Silences false positive issue for string copy operation to buffer of size GMAPSET_MAX from G_mapset().
  • Loading branch information
nilason authored Oct 14, 2024
1 parent e139a4c commit 61b380f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/raster/mask_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ int Rast__mask_info(char *name, char *mapset)
char rname[GNAME_MAX], rmapset[GMAPSET_MAX];

strcpy(rname, "MASK");
strcpy(rmapset, G_mapset());
(void)G_strlcpy(rmapset, G_mapset(), GMAPSET_MAX);

if (!G_find_raster(rname, rmapset))
return -1;
Expand Down
2 changes: 2 additions & 0 deletions raster/r.mask.status/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ int report_status(struct Parameters *params)
else
json_object_set_null(root_object, "is_reclass_of");
char *serialized_string = json_serialize_to_string_pretty(root_value);
if (!serialized_string)
G_fatal_error(_("Failed to initialize pretty JSON string."));
puts(serialized_string);
json_free_serialized_string(serialized_string);
json_value_free(root_value);
Expand Down

0 comments on commit 61b380f

Please sign in to comment.