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

ps.map: Fix copy into fixed size buffer issue in do_scalebar.c file #4307

Merged
merged 7 commits into from
Sep 12, 2024
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions ps/ps.map/do_scalebar.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <grass/glocale.h>
#include "local_proto.h"
#include "distance.h"
#include <grass/gis.h>
nilason marked this conversation as resolved.
Show resolved Hide resolved

#define LEFT 0
#define RIGHT 1
Expand Down Expand Up @@ -181,18 +182,23 @@ int do_scalebar(void)
}

/* draw units label */
if (sb.units == SB_UNITS_AUTO)
strcpy(num, G_database_unit_name(TRUE));
if (sb.units == SB_UNITS_AUTO) {
if (G_strlcpy(num, G_database_unit_name(TRUE), sizeof(num)) >=
sizeof(num)) {
G_fatal_error(_("Unit name <%s> is too long"),
G_database_unit_name(TRUE));
}
}
else if (sb.units == SB_UNITS_METERS)
strcpy(num, _("meters"));
(void)G_strlcpy(num, _("meters"), sizeof(num));
else if (sb.units == SB_UNITS_KM)
strcpy(num, _("kilometers"));
(void)G_strlcpy(num, _("kilometers"), sizeof(num));
else if (sb.units == SB_UNITS_FEET)
strcpy(num, _("feet"));
(void)G_strlcpy(num, _("feet"), sizeof(num));
else if (sb.units == SB_UNITS_MILES)
strcpy(num, _("miles"));
(void)G_strlcpy(num, _("miles"), sizeof(num));
else if (sb.units == SB_UNITS_NMILES)
strcpy(num, _("nautical miles"));
(void)G_strlcpy(num, _("nautical miles"), sizeof(num));

text_box_path(72.0 * (x + length / 2),
72.0 * (PS.page_height - (sb.y + 0.075)), CENTER, UPPER, num,
Expand Down
Loading