summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2013-02-27 17:01:12 +0100
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2013-02-27 17:01:12 +0100
commit2ec84d6a96600f5e5a9e50ec7e98e20b8af472d3 (patch)
tree293dd4ccb48f1c6a9e63cbcf7a2508e07529015e
parentd761d061a8c0240a09e11d973b2bfe50e96f8a22 (diff)
downloadgnutls-2ec84d6a96600f5e5a9e50ec7e98e20b8af472d3.tar.gz
small optimizations in session storage
-rw-r--r--lib/gnutls_db.h2
-rw-r--r--lib/gnutls_int.h2
-rw-r--r--lib/gnutls_record.c3
-rw-r--r--lib/gnutls_session_pack.c21
4 files changed, 15 insertions, 13 deletions
diff --git a/lib/gnutls_db.h b/lib/gnutls_db.h
index ca698e4a2d..4dc8c77858 100644
--- a/lib/gnutls_db.h
+++ b/lib/gnutls_db.h
@@ -25,4 +25,4 @@ int _gnutls_server_restore_session (gnutls_session_t session,
uint8_t * session_id,
int session_id_size);
-#define PACKED_SESSION_MAGIC 0xfadebade
+#define PACKED_SESSION_MAGIC 0xfadebadd
diff --git a/lib/gnutls_int.h b/lib/gnutls_int.h
index e5ed413609..8c58b4abd1 100644
--- a/lib/gnutls_int.h
+++ b/lib/gnutls_int.h
@@ -518,7 +518,7 @@ typedef struct
time_t timestamp;
/* if non-zero the new record padding is used */
- unsigned int new_record_padding;
+ uint8_t new_record_padding;
/* The send size is the one requested by the programmer.
* The recv size is the one negotiated with the peer.
diff --git a/lib/gnutls_record.c b/lib/gnutls_record.c
index 5b7d47e465..d1b242749d 100644
--- a/lib/gnutls_record.c
+++ b/lib/gnutls_record.c
@@ -500,6 +500,9 @@ _gnutls_send_tlen_int (gnutls_session_t session, content_type_t type,
}
else
send_data_size = data_size;
+
+ if (unlikely(send_data_size == 0))
+ return gnutls_assert_val(GNUTLS_E_INTERNAL_ERROR);
/* Only encrypt if we don't have data to send
* from the previous run. - probably interrupted.
diff --git a/lib/gnutls_session_pack.c b/lib/gnutls_session_pack.c
index d3088fb349..035e0f86fe 100644
--- a/lib/gnutls_session_pack.c
+++ b/lib/gnutls_session_pack.c
@@ -97,7 +97,6 @@ _gnutls_session_pack (gnutls_session_t session,
id = gnutls_auth_get_type (session);
- /* first is the timestamp */
BUFFER_APPEND_NUM(&sb, PACKED_SESSION_MAGIC);
BUFFER_APPEND_NUM(&sb, session->security_parameters.timestamp);
BUFFER_APPEND (&sb, &id, 1);
@@ -205,10 +204,12 @@ _gnutls_session_unpack (gnutls_session_t session,
_gnutls_free_auth_info (session);
}
- /* the timestamp is first */
BUFFER_POP_NUM (&sb, magic);
if (magic != PACKED_SESSION_MAGIC)
- return gnutls_assert_val(GNUTLS_E_DB_ERROR);
+ {
+ ret = gnutls_assert_val(GNUTLS_E_DB_ERROR);
+ goto error;
+ }
BUFFER_POP_NUM (&sb, session->internals.resumed_security_parameters.timestamp);
BUFFER_POP (&sb, &id, 1);
@@ -789,13 +790,13 @@ pack_security_parameters (gnutls_session_t session, gnutls_buffer_st * ps)
BUFFER_APPEND (ps, session->security_parameters.server_random,
GNUTLS_RANDOM_SIZE);
- BUFFER_APPEND_NUM (ps, session->security_parameters.session_id_size);
+ BUFFER_APPEND (ps, &session->security_parameters.session_id_size, 1);
BUFFER_APPEND (ps, session->security_parameters.session_id,
session->security_parameters.session_id_size);
BUFFER_APPEND_NUM (ps, session->security_parameters.max_record_send_size);
BUFFER_APPEND_NUM (ps, session->security_parameters.max_record_recv_size);
- BUFFER_APPEND_NUM (ps, session->security_parameters.new_record_padding);
+ BUFFER_APPEND (ps, &session->security_parameters.new_record_padding, 1);
BUFFER_APPEND_NUM (ps, session->security_parameters.ecc_curve);
_gnutls_write_uint32 (ps->length - cur_size, ps->data + size_offset);
@@ -842,9 +843,8 @@ unpack_security_parameters (gnutls_session_t session, gnutls_buffer_st * ps)
BUFFER_POP (ps,
session->internals.resumed_security_parameters.server_random,
GNUTLS_RANDOM_SIZE);
- BUFFER_POP_NUM (ps,
- session->internals.
- resumed_security_parameters.session_id_size);
+ BUFFER_POP (ps, &session->internals.
+ resumed_security_parameters.session_id_size, 1);
BUFFER_POP (ps, session->internals.resumed_security_parameters.session_id,
session->internals.resumed_security_parameters.session_id_size);
@@ -856,8 +856,7 @@ unpack_security_parameters (gnutls_session_t session, gnutls_buffer_st * ps)
session->internals.
resumed_security_parameters.max_record_recv_size);
- BUFFER_POP_NUM (ps,
- session->internals.resumed_security_parameters.new_record_padding);
+ BUFFER_POP (ps, &session->internals.resumed_security_parameters.new_record_padding, 1);
BUFFER_POP_NUM (ps,
session->internals.resumed_security_parameters.ecc_curve);
@@ -942,7 +941,7 @@ gnutls_session_set_premaster (gnutls_session_t session, unsigned int entity,
session->internals.resumed_security_parameters.max_record_send_size =
session->internals.resumed_security_parameters.max_record_recv_size = DEFAULT_MAX_RECORD_SIZE;
- session->internals.resumed_security_parameters.timestamp = time(0);
+ session->internals.resumed_security_parameters.timestamp = gnutls_time(0);
session->internals.resumed_security_parameters.ecc_curve = GNUTLS_ECC_CURVE_INVALID;