]> git.meshlink.io Git - meshlink/commitdiff
Dejavu: Use snprintf() instead of xasprintf() when generating filenames
authorSaverio Proto <zioproto@gmail.com>
Thu, 24 Apr 2014 14:21:36 +0000 (16:21 +0200)
committerSaverio Proto <zioproto@gmail.com>
Thu, 24 Apr 2014 14:21:36 +0000 (16:21 +0200)
src/invitation.c

index db9d96291854799e19ed4f947dc4fcba6e599a22..14a4120c80719af6270f28706250c28a43fab607 100644 (file)
@@ -563,8 +563,8 @@ make_names:
 
        fprintf(f, "Name = %s\n", name);
 
-       char *filename;
-       xasprintf(&filename, "%s" SLASH "%s", hosts_dir, name);
+       char filename[PATH_MAX];
+       snprintf(filename,PATH_MAX, "%s" SLASH "%s", hosts_dir, name);
        FILE *fh = fopen(filename, "w");
        if(!fh) {
                fprintf(stderr, "Could not create file %s: %s\n", filename, strerror(errno));
@@ -624,7 +624,6 @@ make_names:
        }
 
        fclose(f);
-       free(filename);
 
        while(l && !strcasecmp(l, "Name")) {
                if(!check_id(value)) {
@@ -637,7 +636,7 @@ make_names:
                        return false;
                }
 
-               xasprintf(&filename, "%s" SLASH "%s", hosts_dir, value);
+               snprintf(filename,PATH_MAX, "%s" SLASH "%s", hosts_dir, value);
                f = fopen(filename, "w");
 
                if(!f) {
@@ -665,7 +664,6 @@ make_names:
                }
 
                fclose(f);
-               free(filename);
        }
 
        // Generate our key and send a copy to the server
@@ -677,7 +675,7 @@ make_names:
        if(!b64key)
                return false;
 
-       xasprintf(&filename, "%s" SLASH "ecdsa_key.priv", confbase);
+       snprintf(filename,PATH_MAX, "%s" SLASH "ecdsa_key.priv", confbase);
        f = fopenmask(filename, "w", 0600);
 
        if(!ecdsa_write_pem_private_key(key, f)) {