Use stack-allocated strings for temporary filenames.
authorGuus Sliepen <guus@tinc-vpn.org>
Fri, 6 Oct 2017 19:39:24 +0000 (21:39 +0200)
committerGuus Sliepen <guus@tinc-vpn.org>
Fri, 6 Oct 2017 19:39:24 +0000 (21:39 +0200)
src/conf.c
src/tincd.c

index 997a05e82e9aab307f83154e5ab3ed84861d0e11..2e13e4564fd142d809f84e5d827bee47b0d33716 100644 (file)
@@ -487,6 +487,7 @@ FILE *ask_and_open(const char *filename, const char *what) {
        FILE *r;
        char *directory;
        char line[PATH_MAX];
+       char abspath[PATH_MAX];
        const char *fn;
 
        /* Check stdin and stdout */
@@ -520,12 +521,10 @@ FILE *ask_and_open(const char *filename, const char *what) {
        if(fn[0] != '/') {
 #endif
                /* The directory is a relative path or a filename. */
-               char *p;
-
                directory = get_current_dir_name();
-               xasprintf(&p, "%s/%s", directory, fn);
+               snprintf(abspath, sizeof abspath, "%s/%s", directory, fn);
                free(directory);
-               fn = p;
+               fn = abspath;
        }
 
        umask(0077);                            /* Disallow everything for group and other */
index 22fb726aaf88b61e733799195d5245b5247654a7..84ce0d45e4c41d9eafad5a2402c5c5406f3fd360 100644 (file)
@@ -390,7 +390,7 @@ static bool keygen(int bits) {
        BIGNUM *e = NULL;
        RSA *rsa_key;
        FILE *f;
-       char *pubname, *privname;
+       char filename[PATH_MAX];
        BN_GENCB *cb;
        int result;
 
@@ -417,9 +417,8 @@ static bool keygen(int bits) {
        } else
                fprintf(stderr, "Done.\n");
 
-       xasprintf(&privname, "%s/rsa_key.priv", confbase);
-       f = ask_and_open(privname, "private RSA key");
-       free(privname);
+       snprintf(filename, sizeof filename, "%s/rsa_key.priv", confbase);
+       f = ask_and_open(filename, "private RSA key");
 
        if(!f)
                return false;
@@ -436,14 +435,13 @@ static bool keygen(int bits) {
        char *name = get_name();
 
        if(name) {
-               xasprintf(&pubname, "%s/hosts/%s", confbase, name);
+               snprintf(filename, sizeof filename, "%s/hosts/%s", confbase, name);
                free(name);
        } else {
-               xasprintf(&pubname, "%s/rsa_key.pub", confbase);
+               snprintf(filename, sizeof filename, "%s/rsa_key.pub", confbase);
        }
 
-       f = ask_and_open(pubname, "public RSA key");
-       free(pubname);
+       f = ask_and_open(filename, "public RSA key");
 
        if(!f)
                return false;