]> git.meshlink.io Git - meshlink/commitdiff
Validate Name before using it in a filename when generating a keypair.
authorGuus Sliepen <guus@tinc-vpn.org>
Tue, 20 Jan 2009 13:21:50 +0000 (14:21 +0100)
committerGuus Sliepen <guus@tinc-vpn.org>
Tue, 20 Jan 2009 13:21:50 +0000 (14:21 +0100)
src/tincd.c

index c4e8fad3746cd5d11a430a245b41e2a72563a788..5fedd6927174d65e151cadf4338639228f9a6880 100644 (file)
@@ -292,6 +292,18 @@ static bool keygen(int bits)
        char *name = NULL;
        char *filename;
 
+       get_config_string(lookup_config(config_tree, "Name"), &name);
+
+       if(name) {
+               if(!check_id(name)) {
+                       fprintf(stderr, _("Invalid name for myself!\n"));
+                       return false;
+               }
+               asprintf(&filename, "%s/hosts/%s", confbase, name);
+               free(name);
+       } else
+               asprintf(&filename, "%s/rsa_key.pub", confbase);
+
        fprintf(stderr, _("Generating %d bits keys:\n"), bits);
        rsa_key = RSA_generate_key(bits, 0x10001, indicator, NULL);
 
@@ -319,13 +331,6 @@ static bool keygen(int bits)
        fclose(f);
        free(filename);
 
-       get_config_string(lookup_config(config_tree, "Name"), &name);
-
-       if(name)
-               asprintf(&filename, "%s/hosts/%s", confbase, name);
-       else
-               asprintf(&filename, "%s/rsa_key.pub", confbase);
-
        f = ask_and_open(filename, _("public RSA key"), "a");
 
        if(!f)