소스 검색

Removed unused I_location_info() from i.group (ticket https://trac.osgeo.org/grass/ticket/1039). Modified
I_location_info() to avoid buffer overflows.


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@41880 15284696-431f-4ddb-bdfa-cd5b030d7da7

Soeren Gebbert 15 년 전
부모
커밋
f203d1c34d
3개의 변경된 파일9개의 추가작업 그리고 10개의 파일을 삭제
  1. 0 4
      imagery/i.group/main.c
  2. 1 1
      include/imagedefs.h
  3. 8 5
      lib/imagery/loc_info.c

+ 0 - 4
imagery/i.group/main.c

@@ -39,7 +39,6 @@ static int remove_subgroup_files(char group[INAME_LEN],
 
 int main(int argc, char *argv[])
 {
-    char title[80];
     char group[GNAME_MAX], mapset[GMAPSET_MAX];
     int m, k = 0;
 
@@ -102,9 +101,6 @@ int main(int argc, char *argv[])
     if (k < 1 && !l->answer)	/* remove if input is requirement */
 	G_fatal_error(_("No input raster map(s) specified"));
 
-
-    I_location_info(title, argv[0]);	/* unused? */
-
     /* check if current mapset:  (imagery libs are very lacking in this dept)
        - abort if not,
        - remove @mapset part if it is

+ 1 - 1
include/imagedefs.h

@@ -59,7 +59,7 @@ int I_list_subgroup(const char *, const char *, const struct Ref *, FILE *);
 int I_list_subgroup_simple(const struct Ref *, FILE *);
 
 /* loc_info.c */
-int I_location_info(char *, const char *);
+char *I_location_info(const char *);
 
 /* points.c */
 int I_new_control_point(struct Control_Points *, double, double, double,

+ 8 - 5
lib/imagery/loc_info.c

@@ -3,16 +3,19 @@
 #include <grass/gis.h>
 
 /* makes a three part title with location, mapset info */
-int I_location_info(char *buf, const char *middle)
+char *I_location_info(const char *middle)
 {
     char left[80];
     char right[80];
-    int len;
+    char *buf;
+    int len, buf_len;
 
-    sprintf(left, "LOCATION: %s", G_location());
-    sprintf(right, "MAPSET: %s", G_mapset());
+    G_snprintf(left, 80, "LOCATION: %s", G_location());
+    G_snprintf(right, 80, "MAPSET: %s", G_mapset());
     len = 79 - strlen(left) - strlen(middle) - strlen(right);
-    sprintf(buf, "%s%*s%s%*s%s",
+    buf_len = len + strlen(left) + strlen(middle) + strlen(right);
+    buf = (char*)G_calloc(buf_len, sizeof(char));
+    G_snprintf(buf, buf_len, "%s%*s%s%*s%s",
 	    left, len / 2, "", middle, len / 2, "", right);
 
     return 0;