From: Guus Sliepen Date: Sat, 13 Nov 2010 14:55:38 +0000 (+0100) Subject: Use variable length arrays instead of alloca(). X-Git-Tag: release-1.0.14~32 X-Git-Url: https://tinc-vpn.org/git/browse?p=tinc;a=commitdiff_plain;h=9e3ca397735077f85bbde48c36e1b3e0fa950988;ds=sidebyside Use variable length arrays instead of alloca(). --- diff --git a/src/process.c b/src/process.c index f2fff1dc..b3054561 100644 --- a/src/process.c +++ b/src/process.c @@ -397,7 +397,7 @@ bool execute_script(const char *name, char **envp) { for(i = 0; envp[i]; i++) { char *e = strchr(envp[i], '='); if(e) { - p = alloca(e - envp[i] + 1); + p[e - envp[i] + 1]; strncpy(p, envp[i], e - envp[i]); p[e - envp[i]] = '\0'; putenv(p); diff --git a/src/protocol_auth.c b/src/protocol_auth.c index 3f4fa010..cde7ead9 100644 --- a/src/protocol_auth.c +++ b/src/protocol_auth.c @@ -109,15 +109,13 @@ bool id_h(connection_t *c) { } bool send_metakey(connection_t *c) { - char *buffer; - int len; bool x; - len = RSA_size(c->rsa_key); + int len = RSA_size(c->rsa_key); /* Allocate buffers for the meta key */ - buffer = alloca(2 * len + 1); + char buffer[2 * len + 1]; c->outkey = xrealloc(c->outkey, len); @@ -287,16 +285,13 @@ bool metakey_h(connection_t *c) { } bool send_challenge(connection_t *c) { - char *buffer; - int len; - /* CHECKME: what is most reasonable value for len? */ - len = RSA_size(c->rsa_key); + int len = RSA_size(c->rsa_key); /* Allocate buffers for the challenge */ - buffer = alloca(2 * len + 1); + char buffer[2 * len + 1]; c->hischallenge = xrealloc(c->hischallenge, len); diff --git a/src/protocol_key.c b/src/protocol_key.c index 22692bb6..b326b8d7 100644 --- a/src/protocol_key.c +++ b/src/protocol_key.c @@ -145,8 +145,6 @@ bool req_key_h(connection_t *c) { } bool send_ans_key(node_t *to) { - char *key; - // Set key parameters to->incipher = myself->incipher; to->inkeylength = myself->inkeylength; @@ -168,7 +166,7 @@ bool send_ans_key(node_t *to) { memset(to->late, 0, sizeof(to->late)); // Convert to hexadecimal and send - key = alloca(2 * to->inkeylength + 1); + char key[2 * to->inkeylength + 1]; bin2hex(to->inkey, key, to->inkeylength); key[to->inkeylength * 2] = '\0';