Skip to content

Commit

Permalink
lib/vector/Vlib: Fix copy into buffer size issue in color_read.c (#4462)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShubhamDesai authored Oct 12, 2024
1 parent 0feea31 commit 9df8433
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/vector/Vlib/color_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ int Vect_read_colors(const char *name, const char *mapset,
if (colors)
Rast_init_colors(colors);

strcpy(xname, name);
if (G_strlcpy(xname, name, sizeof(xname)) >= sizeof(xname)) {
G_warning(_("Vector map name <%s> is too long"), name);
return -1;
}
mapset = G_find_vector(xname, mapset);
if (!mapset)
return -1;
Expand All @@ -58,12 +61,12 @@ int Vect_read_colors(const char *name, const char *mapset,

if (strcmp(mapset, G_mapset()) == 0) {
/* look for the regular color table */
sprintf(buf, "%s/%s", GV_DIRECTORY, name);
(void)snprintf(buf, sizeof(buf), "%s/%s", GV_DIRECTORY, name);
ret = Rast__read_colors(buf, GV_COLR_ELEMENT, mapset, colors);
}
else {
/* look for secondary color table in current mapset */
sprintf(buf, "%s/%s", GV_COLR2_DIRECTORY, mapset);
(void)snprintf(buf, sizeof(buf), "%s/%s", GV_COLR2_DIRECTORY, mapset);
ret = Rast__read_colors(buf, name, G_mapset(), colors);
}
if (ret == -2)
Expand Down

0 comments on commit 9df8433

Please sign in to comment.