diff options
author | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2017-09-29 09:01:41 +0200 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2018-02-19 15:29:35 +0100 |
commit | 8c107a11041c6a093dca78fd159f88dbfb307bbc (patch) | |
tree | 9063463b49fdf40ac414924a1b55d7e18b51b8b5 | |
parent | aeb3353b48dfe08c851dc53bdc1914d3173d5909 (diff) | |
download | gnutls-8c107a11041c6a093dca78fd159f88dbfb307bbc.tar.gz |
handshake: simplified version parsing
Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
-rw-r--r-- | lib/algorithms.h | 1 | ||||
-rw-r--r-- | lib/algorithms/protocols.c | 11 | ||||
-rw-r--r-- | lib/handshake.c | 14 |
3 files changed, 19 insertions, 7 deletions
diff --git a/lib/algorithms.h b/lib/algorithms.h index 3ff73a99ed..e96689208c 100644 --- a/lib/algorithms.h +++ b/lib/algorithms.h @@ -45,6 +45,7 @@ /* Functions for version handling. */ const version_entry_st *version_to_entry(gnutls_protocol_t version); +const version_entry_st *nversion_to_entry(uint8_t major, uint8_t minor); const version_entry_st *_gnutls_version_lowest(gnutls_session_t session); const version_entry_st *_gnutls_legacy_version_max(gnutls_session_t session); diff --git a/lib/algorithms/protocols.c b/lib/algorithms/protocols.c index 36e1717703..be02246537 100644 --- a/lib/algorithms/protocols.c +++ b/lib/algorithms/protocols.c @@ -193,6 +193,17 @@ const version_entry_st *version_to_entry(gnutls_protocol_t version) return NULL; } +const version_entry_st *nversion_to_entry(uint8_t major, uint8_t minor) +{ + const version_entry_st *p; + + for (p = sup_versions; p->name != NULL; p++) { + if ((p->major == major) && (p->minor == minor)) + return p; + } + return NULL; +} + static int version_is_valid_for_session(gnutls_session_t session, const version_entry_st *v) diff --git a/lib/handshake.c b/lib/handshake.c index bf2b029db3..2a041ec611 100644 --- a/lib/handshake.c +++ b/lib/handshake.c @@ -1566,7 +1566,6 @@ read_server_hello(gnutls_session_t session, uint8_t session_id_len = 0; int pos = 0; int ret = 0; - gnutls_protocol_t version; int len = datalen; const version_entry_st *vers; gnutls_ext_flags_t ext_parse_flag; @@ -1580,21 +1579,22 @@ read_server_hello(gnutls_session_t session, session, data[pos], data[pos + 1]); DECR_LEN(len, 2); - version = _gnutls_version_get(data[pos], data[pos + 1]); - if (_gnutls_version_is_supported(session, version) == 0) { + vers = nversion_to_entry(data[pos], data[pos + 1]); + if (unlikely(vers == NULL)) + return gnutls_assert_val(GNUTLS_E_UNSUPPORTED_VERSION_PACKET); + + if (_gnutls_version_is_supported(session, vers->id) == 0) { gnutls_assert(); return GNUTLS_E_UNSUPPORTED_VERSION_PACKET; } - if (_gnutls_set_current_version(session, version) < 0) + if (_gnutls_set_current_version(session, vers->id) < 0) return gnutls_assert_val(GNUTLS_E_UNSUPPORTED_VERSION_PACKET); - vers = get_version(session); - pos += 2; DECR_LEN(len, GNUTLS_RANDOM_SIZE); - ret = _gnutls_set_server_random(session, version, &data[pos]); + ret = _gnutls_set_server_random(session, vers->id, &data[pos]); if (ret < 0) return gnutls_assert_val(ret); |