From: Guus Sliepen Date: Tue, 22 Jun 2021 20:36:13 +0000 (+0200) Subject: Fix warnings from GCC about VLAs. X-Git-Tag: release-1.1pre18~13 X-Git-Url: https://tinc-vpn.org/git/browse?a=commitdiff_plain;h=b2fe16d635dded2d6c3096d85672696d0b82dcd1;p=tinc Fix warnings from GCC about VLAs. --- diff --git a/src/fsck.c b/src/fsck.c index 3804f2d8..f772d587 100644 --- a/src/fsck.c +++ b/src/fsck.c @@ -385,26 +385,38 @@ int fsck(const char *argv0) { return 1; } - char buf1[len], buf2[len], buf3[len]; - randomize(buf1, sizeof(buf1)); - buf1[0] &= 0x7f; - memset(buf2, 0, sizeof(buf2)); - memset(buf3, 0, sizeof(buf2)); + char *buf1 = malloc(len); + char *buf2 = malloc(len); + char *buf3 = malloc(len); - if(!rsa_public_encrypt(rsa_pub, buf1, sizeof(buf1), buf2)) { + randomize(buf1, len); + buf1[0] &= 0x7f; + memset(buf2, 0, len); + memset(buf3, 0, len); + bool result = false; + + if(rsa_public_encrypt(rsa_pub, buf1, len, buf2)) { + if(rsa_private_decrypt(rsa_priv, buf2, len, buf3)) { + if(memcmp(buf1, buf3, len)) { + result = true; + } else { + fprintf(stderr, "ERROR: public and private RSA keys do not match.\n"); + } + } else { + fprintf(stderr, "ERROR: private RSA key does not work.\n"); + } + } else { fprintf(stderr, "ERROR: public RSA key does not work.\n"); - return 1; } - if(!rsa_private_decrypt(rsa_priv, buf2, sizeof(buf2), buf3)) { - fprintf(stderr, "ERROR: private RSA key does not work.\n"); - return 1; - } + free(buf3); + free(buf2); + free(buf1); - if(memcmp(buf1, buf3, sizeof(buf1))) { - fprintf(stderr, "ERROR: public and private RSA keys do not match.\n"); + if(!result) { return 1; } + } } else { if(rsa_pub) {