[GRASS-SVN] r52729 - grass/trunk/ps/ps.map
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Aug 19 06:23:25 PDT 2012
Author: mmetz
Date: 2012-08-19 06:23:25 -0700 (Sun, 19 Aug 2012)
New Revision: 52729
Modified:
grass/trunk/ps/ps.map/local_proto.h
grass/trunk/ps/ps.map/main.c
grass/trunk/ps/ps.map/r_cell.c
grass/trunk/ps/ps.map/r_instructions.c
Log:
fix various bugs introduced with r45580 including memory corruption, fix buffer overflow
Modified: grass/trunk/ps/ps.map/local_proto.h
===================================================================
--- grass/trunk/ps/ps.map/local_proto.h 2012-08-19 13:23:07 UTC (rev 52728)
+++ grass/trunk/ps/ps.map/local_proto.h 2012-08-19 13:23:25 UTC (rev 52729)
@@ -199,9 +199,7 @@
void print_papers(void);
/* r_instructions.c */
-void read_instructions(FILE *, struct PS_data *, int, int, int,
- struct scalebar *, int *, int *,
- struct PS_group *);
+void read_instructions(int, int);
/* r_border.c */
int read_border(void);
Modified: grass/trunk/ps/ps.map/main.c
===================================================================
--- grass/trunk/ps/ps.map/main.c 2012-08-19 13:23:07 UTC (rev 52728)
+++ grass/trunk/ps/ps.map/main.c 2012-08-19 13:23:25 UTC (rev 52729)
@@ -137,7 +137,11 @@
if (G_parser(argc, argv))
exit(EXIT_FAILURE);
-
+
+ /* PS.map_* variables are set to 0 (not defined) and then may be
+ * reset by 'maploc'. When script is read, main() should call
+ * reset_map_location() to reset map size to fit to paper */
+
G_zero(&PS, sizeof(struct PS_data));
/* Print paper sizes to stdout */
@@ -193,10 +197,6 @@
PS.cell_fd = -1;
PS.do_border = TRUE;
- /* PS.map_* variables are set to 0 (not defined) and then may be
- * reset by 'maploc'. When script is read, main() should call
- * reset_map_location() to reset map size to fit to paper */
-
/* arguments */
if (input_file->answer) {
if (strcmp(input_file->answer, "-")) {
@@ -243,8 +243,7 @@
G_get_set_window(&PS.w);
Rast_set_window(&PS.w);
- read_instructions(inputfd, &PS, copies_set, ps_copies, can_reset_scale,
- &sb, &do_mapinfo, &do_vlegend, &grp);
+ read_instructions(copies_set, can_reset_scale);
/* reset map location base on 'paper' on 'location' */
reset_map_location();
Modified: grass/trunk/ps/ps.map/r_cell.c
===================================================================
--- grass/trunk/ps/ps.map/r_cell.c 2012-08-19 13:23:07 UTC (rev 52728)
+++ grass/trunk/ps/ps.map/r_cell.c 2012-08-19 13:23:25 UTC (rev 52729)
@@ -10,7 +10,8 @@
int read_cell(char *name, char *mapset)
{
- char fullname[100];
+ /* full name can be "name at mapset in mapset" */
+ char fullname[GNAME_MAX + 2 * GMAPSET_MAX + 4];
PS.do_colortable = 0;
if (PS.cell_fd >= 0) {
Modified: grass/trunk/ps/ps.map/r_instructions.c
===================================================================
--- grass/trunk/ps/ps.map/r_instructions.c 2012-08-19 13:23:07 UTC (rev 52728)
+++ grass/trunk/ps/ps.map/r_instructions.c 2012-08-19 13:23:25 UTC (rev 52729)
@@ -7,6 +7,11 @@
#define KEY(x) (strcmp(key,x)==0)
+extern FILE *inputfd;
+extern int do_mapinfo;
+extern int do_vlegend;
+extern int ps_copies;
+
static char *help[] = {
"rast rastermap setcolor val_range(s) color",
"vpoints vector points map scalebar [f|s]",
@@ -26,14 +31,12 @@
""
};
-void read_instructions(FILE *inputfd, struct PS_data *PS,
- int copies_set, int ps_copies, int can_reset_scale,
- struct scalebar *sb, int *do_mapinfo, int *do_vlegend,
- struct PS_group *grp)
+void read_instructions(int copies_set, int can_reset_scale)
{
int i;
int iflag;
- char name[GNAME_MAX], mapset[GMAPSET_MAX];
+ /* name can be fully qualified */
+ char name[GNAME_MAX + GMAPSET_MAX], mapset[GMAPSET_MAX];
char buf[1024];
iflag = 0;
@@ -44,8 +47,17 @@
if (!input(1, buf, help)) {
if (!iflag) {
- if (G_getl2(buf, 12, inputfd))
- G_warning(_("Data exists after final 'end' instruction!"));
+ /* TODO: check also if instructions are piped in
+ * through stdin, not interactive */
+ if (inputfd != stdin) {
+ while (G_getl2(buf, 12, inputfd)) {
+ /* empty lines and comments are fine */
+ if (key_data(buf, &key, &data))
+ G_warning(_("Data exist after final 'end' instruction!"));
+ }
+ fclose(inputfd);
+ inputfd = stdin;
+ }
break;
}
iflag = 0;
@@ -86,11 +98,11 @@
n = sscanf(data, "%lf %lf %lf %lf", &x, &y, &w, &h);
if (n == 2 || n == 4) {
- PS->map_x_orig = x;
- PS->map_y_loc = y;
+ PS.map_x_orig = x;
+ PS.map_y_loc = y;
if (n == 4) {
- PS->map_width = w;
- PS->map_height = h;
+ PS.map_width = w;
+ PS.map_height = h;
}
}
else {
@@ -122,7 +134,7 @@
char colorbuf[100];
char catsbuf[100];
- if (PS->cell_fd < 0)
+ if (PS.cell_fd < 0)
error(key, data, _("no raster map selected yet"));
if (sscanf(data, "%s %[^\n]", catsbuf, colorbuf) == 2) {
@@ -131,11 +143,11 @@
error(key, colorbuf, _("illegal color request"));
if (strncmp(catsbuf, "null", 4) == 0) {
- Rast_set_null_value_color(r, g, b, &(PS->colors));
+ Rast_set_null_value_color(r, g, b, &(PS.colors));
continue;
}
if (strncmp(catsbuf, "default", 7) == 0) {
- Rast_set_default_color(r, g, b, &(PS->colors));
+ Rast_set_default_color(r, g, b, &(PS.colors));
continue;
}
if ((count = parse_val_list(catsbuf, &val_list)) < 0)
@@ -145,7 +157,7 @@
dmin = val_list[i];
dmax = val_list[i + 1];
Rast_add_d_color_rule(&dmin, r, g, b, &dmax, r, g, b,
- &(PS->colors));
+ &(PS.colors));
}
G_free(val_list);
}
@@ -153,21 +165,21 @@
}
if (KEY("colortable")) {
- PS->do_colortable = 0;
+ PS.do_colortable = 0;
/*
- if (PS->cell_fd < 0)
+ if (PS.cell_fd < 0)
error(key, data, "no raster map selected yet");
else
*/
- PS->do_colortable = yesno(key, data);
- if (PS->do_colortable)
+ PS.do_colortable = yesno(key, data);
+ if (PS.do_colortable)
read_colortable();
continue;
}
if (KEY("border")) {
- PS->do_border = yesno(key, data);
- if (PS->do_border)
+ PS.do_border = yesno(key, data);
+ if (PS.do_border)
read_border();
continue;
}
@@ -178,11 +190,11 @@
_("scalebar is not appropriate for this projection"));
gobble_input();
}
- PS->do_scalebar = 1;
- if (sscanf(data, "%s", sb->type) != 1)
- strcpy(sb->type, "f"); /* default to fancy scalebar */
+ PS.do_scalebar = 1;
+ if (sscanf(data, "%s", sb.type) != 1)
+ strcpy(sb.type, "f"); /* default to fancy scalebar */
read_scalebar();
- if (sb->length <= 0.) {
+ if (sb.length <= 0.) {
error(key, data, _("Bad scalebar length"));
gobble_input();
}
@@ -285,9 +297,9 @@
if (!can_reset_scale)
continue;
if (check_scale(data))
- strcpy(PS->scaletext, data);
+ strcpy(PS.scaletext, data);
else {
- PS->scaletext[0] = 0;
+ PS.scaletext[0] = 0;
error(key, data, _("illegal scale request"));
}
continue;
@@ -301,24 +313,24 @@
if (KEY("header")) {
read_header();
- PS->do_header = 1;
+ PS.do_header = 1;
continue;
}
if (KEY("mapinfo")) {
read_info();
- *do_mapinfo = 1;
+ do_mapinfo = 1;
continue;
}
if (KEY("vlegend")) {
read_vlegend();
- *do_vlegend = 1;
+ do_vlegend = 1;
continue;
}
if (KEY("outline")) {
- if (PS->cell_fd < 0) {
+ if (PS.cell_fd < 0) {
error(key, data, _("no raster map selected yet"));
gobble_input();
}
@@ -336,15 +348,15 @@
if (KEY("greyrast") || KEY("grayrast")) {
if (scan_gis("cell", "raster", key, data, name, mapset, 0))
read_cell(name, mapset);
- PS->grey = 1;
+ PS.grey = 1;
continue;
}
if (KEY("group")) {
G_strip(data);
if (I_find_group(data)) {
- grp->group_name = G_store(data);
- grp->do_group = 1;
+ grp.group_name = G_store(data);
+ grp.do_group = 1;
read_group();
}
else
@@ -354,7 +366,7 @@
if (KEY("rgb")) {
G_strip(data);
- grp->do_group = 1;
+ grp.do_group = 1;
read_rgb(key, data);
continue;
}
@@ -385,11 +397,11 @@
}
if (KEY("grid")) {
- PS->grid = -1;
- PS->grid_numbers = 0;
- sscanf(data, "%d", &(PS->grid));
- if (PS->grid < 0) {
- PS->grid = 0;
+ PS.grid = -1;
+ PS.grid_numbers = 0;
+ sscanf(data, "%d", &(PS.grid));
+ if (PS.grid < 0) {
+ PS.grid = 0;
error(key, data, _("illegal grid spacing"));
gobble_input();
}
@@ -406,11 +418,11 @@
}
/* if (G_projection() == PROJECTION_LL)
G_message(_("geogrid referenced to [???] ellipsoid")); */
- PS->geogrid = -1.;
- PS->geogrid_numbers = 0;
- sscanf(data, "%d %s", &(PS->geogrid), PS->geogridunit);
- if (PS->geogrid < 0) {
- PS->geogrid = 0;
+ PS.geogrid = -1.;
+ PS.geogrid_numbers = 0;
+ sscanf(data, "%d %s", &(PS.geogrid), PS.geogridunit);
+ if (PS.geogrid < 0) {
+ PS.geogrid = 0;
error(key, data, _("illegal geo-grid spacing"));
gobble_input();
}
@@ -420,11 +432,11 @@
}
if (KEY("psfile")) {
- if (PS->num_psfiles >= MAX_PSFILES)
+ if (PS.num_psfiles >= MAX_PSFILES)
continue;
G_strip(data);
- PS->psfiles[PS->num_psfiles] = G_store(data);
- PS->num_psfiles++;
+ PS.psfiles[PS.num_psfiles] = G_store(data);
+ PS.num_psfiles++;
continue;
}
@@ -433,10 +445,10 @@
ret = G_str_to_color(data, &r, &g, &b);
if (ret == 1) {
- PS->mask_r = r / 255.0;
- PS->mask_g = g / 255.0;
- PS->mask_b = b / 255.0;
- PS->mask_color = 1;
+ PS.mask_r = r / 255.0;
+ PS.mask_g = g / 255.0;
+ PS.mask_b = b / 255.0;
+ PS.mask_color = 1;
continue;
}
else if (ret == 2) { /* none */
More information about the grass-commit
mailing list