X-Git-Url: https://www.tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Ftincctl.c;h=3c7d3683e9da4fb375f373f4f4277f8aa13436ca;hb=5a738e685bd002661276cf6938c5b74ef1ec0ccf;hp=87bbfe0187e64e5548e15230143adf5a73393a09;hpb=5e8a37ee797b1bea33760e5e3d3c3a67e7dfbd0d;p=tinc diff --git a/src/tincctl.c b/src/tincctl.c index 87bbfe01..3c7d3683 100644 --- a/src/tincctl.c +++ b/src/tincctl.c @@ -263,19 +263,21 @@ static void disable_old_keys(const char *filename, const char *what) { bool disabled = false; bool block = false; bool error = false; - FILE *r, *w; - r = fopen(filename, "r"); + FILE *r = fopen(filename, "r"); + FILE *w = NULL; if(!r) { return; } - snprintf(tmpfile, sizeof(tmpfile), "%s.tmp", filename); + int result = snprintf(tmpfile, sizeof(tmpfile), "%s.tmp", filename); - struct stat st = {.st_mode = 0600}; - fstat(fileno(r), &st); - w = fopenmask(tmpfile, "w", st.st_mode); + if(result < sizeof(tmpfile)) { + struct stat st = {.st_mode = 0600}; + fstat(fileno(r), &st); + w = fopenmask(tmpfile, "w", st.st_mode); + } while(fgets(buf, sizeof(buf), r)) { if(!block && !strncmp(buf, "-----BEGIN ", 11)) {