From: Frank Lichtenheld <[email protected]> Make sure we have a sane length and convert it int.
Change-Id: I0245175f2884d56838990f53cee6381b981b79c1 Signed-off-by: Frank Lichtenheld <[email protected]> Acked-by: Razvan Cojocaru <[email protected]> Acked-by: Gert Doering <[email protected]> Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2004 --- This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master. Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2004 This mail reflects revision 1 of this Change. Acked-by according to Gerrit (reflected above): Razvan Cojocaru <[email protected]> Gert Doering <[email protected]> diff --git a/src/openvpn/misc.c b/src/openvpn/misc.c index 0e4669a..b420aac 100644 --- a/src/openvpn/misc.c +++ b/src/openvpn/misc.c @@ -72,11 +72,6 @@ #endif } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - #ifdef ENABLE_MANAGEMENT /* Get username/password from the management interface */ static bool @@ -127,19 +122,23 @@ parse_auth_challenge(const char *auth_challenge, struct gc_arena *gc) { ASSERT(auth_challenge); + const size_t len = strlen(auth_challenge); + if (!buf_size_valid(len)) + { + return NULL; + } - struct auth_challenge_info *ac; - const int len = strlen(auth_challenge); - char *work = (char *)gc_malloc(len + 1, false, gc); - const char *cp; + const int work_len = (int)len + 1; + char *work = (char *)gc_malloc(work_len, false, gc); struct buffer b; buf_set_read(&b, (const uint8_t *)auth_challenge, len); + struct auth_challenge_info *ac; ALLOC_OBJ_CLEAR_GC(ac, struct auth_challenge_info, gc); /* parse prefix */ - if (!buf_parse(&b, ':', work, len)) + if (!buf_parse(&b, ':', work, work_len)) { return NULL; } @@ -149,11 +148,11 @@ } /* parse flags */ - if (!buf_parse(&b, ':', work, len)) + if (!buf_parse(&b, ':', work, work_len)) { return NULL; } - for (cp = work; *cp != '\0'; ++cp) + for (const char *cp = work; *cp != '\0'; ++cp) { const char c = *cp; if (c == 'E') @@ -167,14 +166,14 @@ } /* parse state ID */ - if (!buf_parse(&b, ':', work, len)) + if (!buf_parse(&b, ':', work, work_len)) { return NULL; } ac->state_id = string_alloc(work, gc); /* parse user name */ - if (!buf_parse(&b, ':', work, len)) + if (!buf_parse(&b, ':', work, work_len)) { return NULL; } @@ -189,10 +188,6 @@ #endif /* ifdef ENABLE_MANAGEMENT */ -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic pop -#endif - /* * Get and store a username/password */ _______________________________________________ Openvpn-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openvpn-devel
