]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
use stack for file paths
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Sat, 21 Jul 2012 12:14:53 +0000 (14:14 +0200)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Sat, 21 Jul 2012 17:01:47 +0000 (19:01 +0200)
tests/openpgp-auth.c
tests/openpgp-auth2.c

index 503519aa4f84e50f3eeb915c293ec0f8f6be97cc..548d51188ac016d51f96cfe954f1283b9e02b652 100644 (file)
@@ -60,7 +60,7 @@ doit ()
   int err, i;
   int sockets[2];
   const char *srcdir;
-  char *pub_key_path, *priv_key_path;
+  char pub_key_path[512], priv_key_path[512];
   pid_t child;
 
   gnutls_global_init ();
@@ -87,12 +87,16 @@ doit ()
       if (err != 0)
         fail ("socketpair %s\n", strerror (errno));
 
-      pub_key_path = malloc (strlen (srcdir) + strlen (pub_key_file) + 2);
+      if (sizeof(pub_key_path) < strlen (srcdir) + strlen (pub_key_file) + 2)
+        abort();
+
       strcpy (pub_key_path, srcdir);
       strcat (pub_key_path, "/");
       strcat (pub_key_path, pub_key_file);
 
-      priv_key_path = malloc (strlen (srcdir) + strlen (priv_key_file) + 2);
+      if (sizeof(priv_key_path) < strlen (srcdir) + strlen (priv_key_file) + 2)
+        abort();
+
       strcpy (priv_key_path, srcdir);
       strcat (priv_key_path, "/");
       strcat (priv_key_path, priv_key_file);
@@ -267,8 +271,6 @@ doit ()
 
     }
 
-  free(pub_key_path);
-  free(priv_key_path);
   gnutls_global_deinit ();
 }
 #else
index 8877df593fb1ee2a5378a51f77a27b4287675b74..79a7ad9bef2473f79250e79cdbaf7807804f9ef3 100644 (file)
@@ -69,7 +69,7 @@ doit ()
   int err;
   int sockets[2];
   const char *srcdir;
-  char *pub_key_path, *priv_key_path;
+  char pub_key_path[512], priv_key_path[512];
   pid_t child;
 
   gnutls_global_init ();
@@ -86,12 +86,16 @@ doit ()
   if (err != 0)
     fail ("socketpair %s\n", strerror (errno));
 
-  pub_key_path = malloc (strlen (srcdir) + strlen (pub_key_file) + 2);
+  if (sizeof(pub_key_path) < strlen (srcdir) + strlen (pub_key_file) + 2)
+    abort();
+
   strcpy (pub_key_path, srcdir);
   strcat (pub_key_path, "/");
   strcat (pub_key_path, pub_key_file);
 
-  priv_key_path = malloc (strlen (srcdir) + strlen (priv_key_file) + 2);
+  if (sizeof(priv_key_path) < strlen (srcdir) + strlen (priv_key_file) + 2)
+    abort();
+
   strcpy (priv_key_path, srcdir);
   strcat (priv_key_path, "/");
   strcat (priv_key_path, priv_key_file);
@@ -250,8 +254,6 @@ doit ()
         fail ("child failed: %d\n", status);
     }
 
-  free(pub_key_path);
-  free(priv_key_path);
   gnutls_global_deinit ();
 }
 #else