Skip to content

Commit

Permalink
i.topo.corr: Fix Copy into fix Buffer size issue (#4685)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShubhamDesai authored Nov 12, 2024
1 parent b318909 commit cba8a73
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions imagery/i.topo.corr/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,21 @@ int main(int argc, char *argv[])
Rast_get_window(&window);
azimuth = atof(azim->answer);
/* Warning: make buffers and output after set window */
strcpy(dem.name, base->answer);
if (G_strlcpy(dem.name, base->answer, sizeof(dem.name)) >=
sizeof(dem.name)) {
G_fatal_error(_("DEM name <%s> is too long"), base->answer);
}
/* Set window to DEM file */
Rast_get_window(&window);
Rast_get_cellhd(dem.name, "", &hd_dem);
Rast_align_window(&window, &hd_dem);
dem.fd = Rast_open_old(dem.name, "");
dem.type = Rast_get_map_type(dem.fd);
/* Open and buffer of the output file */
strcpy(out.name, output->answer);
if (G_strlcpy(out.name, output->answer, sizeof(out.name)) >=
sizeof(out.name)) {
G_fatal_error(_("Output name <%s> is too long"), output->answer);
}
out.fd = Rast_open_new(output->answer, DCELL_TYPE);
out.rast = Rast_allocate_buf(out.type);
/* Open and buffer of the elevation file */
Expand Down Expand Up @@ -169,7 +175,11 @@ int main(int argc, char *argv[])
for (i = 0; input->answers[i] != NULL; i++) {
G_message(_("Band %s: "), input->answers[i]);
/* Abre fichero de bandas y el de salida */
strcpy(band.name, input->answers[i]);
if (G_strlcpy(band.name, input->answers[i], sizeof(band.name)) >=
sizeof(band.name)) {
G_fatal_error(_("Band name <%s> is too long"),
input->answers[i]);
}
Rast_get_cellhd(band.name, "", &hd_band);
Rast_set_window(
&hd_band); /* Antes de out_open y allocate para mismo size */
Expand Down

0 comments on commit cba8a73

Please sign in to comment.