From 9a27de8caae0f43b3a8dca2f4e750eb93c31bd68 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Wed, 24 Oct 2018 20:06:29 +0200 Subject: [PATCH] access: do not allocate always 50 bytes for aa_representative --- src/access.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/access.c b/src/access.c index 330fb7f4f..02953765b 100644 --- a/src/access.c +++ b/src/access.c @@ -716,6 +716,7 @@ access_get(struct sockaddr_storage *src, const char *username, verify_callback_t access_t *a = access_alloc(); access_entry_t *ae; int nouser = tvh_str_default(username, NULL) == NULL; + char *s; if (!access_noacl && access_ip_blocked(src)) return a; @@ -727,8 +728,9 @@ access_get(struct sockaddr_storage *src, const char *username, verify_callback_t superuser_username, superuser_password)) return access_full(a); } else { - a->aa_representative = malloc(50); - tcp_get_str_from_ip(src, a->aa_representative, 50); + s = alloca(50); + tcp_get_str_from_ip(src, s, 50); + a->aa_representative = strdup(s); if(!passwd_verify2(username, verify, aux, superuser_username, superuser_password)) return access_full(a); @@ -815,9 +817,10 @@ access_get_by_addr(struct sockaddr_storage *src) { access_t *a = access_alloc(); access_entry_t *ae; + char buf[50]; - a->aa_representative = malloc(50); - tcp_get_str_from_ip(src, a->aa_representative, 50); + tcp_get_str_from_ip(src, buf, sizeof(buf)); + a->aa_representative = strdup(buf); if(access_noacl) return access_full(a); -- 2.47.3