Kaynağa Gözat

Use G_asprintf() to avoid buffer overrun

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@38870 15284696-431f-4ddb-bdfa-cd5b030d7da7
Glynn Clements 15 yıl önce
ebeveyn
işleme
874e9c2a3e
1 değiştirilmiş dosya ile 9 ekleme ve 8 silme
  1. 9 8
      general/g.parser/main.c

+ 9 - 8
general/g.parser/main.c

@@ -307,19 +307,20 @@ static int reinvoke_script(const struct context *ctx, const char *filename)
     }
 
     for (option = ctx->first_option; option; option = option->next_opt) {
-	char buff[4096], upper[4096];
+	char upper[4096];
+	char *str;
 
-	sprintf(buff, "GIS_OPT_%s=%s", option->key,
-		option->answer ? option->answer : "");
-	putenv(G_store(buff));
+	G_asprintf(&str, "GIS_OPT_%s=%s", option->key,
+		   option->answer ? option->answer : "");
+	putenv(str);
 
 	strcpy(upper, option->key);
 	G_str_to_upper(upper);
-	sprintf(buff, "GIS_OPT_%s=%s", upper,
-		option->answer ? option->answer : "");
+	G_asprintf(&str, "GIS_OPT_%s=%s", upper,
+		   option->answer ? option->answer : "");
 
-	G_debug(2, "set %s", buff);
-	putenv(G_store(buff));
+	G_debug(2, "set %s", str);
+	putenv(str);
     }
 
 #ifdef __MINGW32__