Skip to content

Commit

Permalink
Fix copy into buffer size issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Shubham Vasudeo Desai committed Oct 5, 2024
1 parent a16a02f commit 4fbcf43
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/vector/Vlib/color_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ 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_fatal_error(_("Vector map name <%s> is too long"), name);
}
mapset = G_find_vector(xname, mapset);
if (!mapset)
return -1;
Expand All @@ -58,12 +60,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);
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);
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 4fbcf43

Please sign in to comment.