Skip to content

Commit

Permalink
Address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
lrstewart committed Dec 21, 2022
1 parent 7172fbe commit 0455969
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
8 changes: 3 additions & 5 deletions tests/unit/s2n_config_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -460,15 +460,13 @@ int main(int argc, char **argv)

/* Test s2n_config_set_send_buffer_size */
{
const uint32_t min_size = S2N_TLS_MAX_RECORD_LEN_FOR(S2N_MIN_SEND_BUFFER_FRAGMENT_SIZE);

/* Safety */
{
DEFER_CLEANUP(struct s2n_config *config = s2n_config_new(), s2n_config_ptr_free);
EXPECT_NOT_NULL(config);

EXPECT_EQUAL(config->send_buffer_size_override, 0);
EXPECT_FAILURE_WITH_ERRNO(s2n_config_set_send_buffer_size(NULL, min_size), S2N_ERR_NULL);
EXPECT_FAILURE_WITH_ERRNO(s2n_config_set_send_buffer_size(NULL, S2N_MIN_SEND_BUFFER_SIZE), S2N_ERR_NULL);
EXPECT_FAILURE_WITH_ERRNO(s2n_config_set_send_buffer_size(config, 0), S2N_ERR_INVALID_ARGUMENT);
EXPECT_EQUAL(config->send_buffer_size_override, 0);
};
Expand All @@ -490,13 +488,13 @@ int main(int argc, char **argv)
{
DEFER_CLEANUP(struct s2n_config *config = s2n_config_new(), s2n_config_ptr_free);
EXPECT_NOT_NULL(config);
EXPECT_SUCCESS(s2n_config_set_send_buffer_size(config, min_size));
EXPECT_SUCCESS(s2n_config_set_send_buffer_size(config, S2N_MIN_SEND_BUFFER_SIZE));

DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_SERVER), s2n_connection_ptr_free);
EXPECT_NOT_NULL(conn);
EXPECT_SUCCESS(s2n_connection_set_config(conn, config));

EXPECT_EQUAL(config->send_buffer_size_override, min_size);
EXPECT_EQUAL(config->send_buffer_size_override, S2N_MIN_SEND_BUFFER_SIZE);
EXPECT_TRUE(conn->multirecord_send);
};
};
Expand Down
16 changes: 7 additions & 9 deletions tests/unit/s2n_send_multirecord_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,18 +194,16 @@ int main(int argc, char **argv)

/* Send buffer was configured too small for even a single record.
* Send smaller records.
*
* The minimum buffer size we allow generates a fragment size of 5, to prevent
* fragmenting KeyUpdate messages, which are always 5 bytes. At this minimum size,
* application data is also fragmented into 5 byte chunks, which is pretty silly,
* but is an edge case.
*/
{
/* The minimum buffer size we allow generates a fragment size of 5, to prevent
* fragmenting KeyUpdate messages, which are always 5 bytes. At this minimum size,
* application data is also fragmented into 5 byte chunks, which is pretty silly,
* but is an edge case.
*/
uint32_t min_buffer_size = S2N_TLS_MAX_RECORD_LEN_FOR(S2N_MIN_SEND_BUFFER_FRAGMENT_SIZE);

DEFER_CLEANUP(struct s2n_config *min_buffer_config = s2n_config_new(), s2n_config_ptr_free);
EXPECT_NOT_NULL(min_buffer_config);
EXPECT_SUCCESS(s2n_config_set_send_buffer_size(min_buffer_config, min_buffer_size));
EXPECT_SUCCESS(s2n_config_set_send_buffer_size(min_buffer_config, S2N_MIN_SEND_BUFFER_SIZE));

DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_CLIENT),
s2n_connection_ptr_free);
Expand All @@ -230,7 +228,7 @@ int main(int argc, char **argv)
EXPECT_TRUE(context.bytes_sent > send_size);

/* Verify output buffer */
EXPECT_EQUAL(conn->out.blob.size, min_buffer_size);
EXPECT_EQUAL(conn->out.blob.size, S2N_MIN_SEND_BUFFER_SIZE);
};

/* Total data fits in multiple records.
Expand Down
2 changes: 1 addition & 1 deletion tls/s2n_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ int s2n_config_client_hello_cb_enable_poll(struct s2n_config *config)
int s2n_config_set_send_buffer_size(struct s2n_config *config, uint32_t size)
{
POSIX_ENSURE_REF(config);
POSIX_ENSURE(size >= S2N_TLS_MAX_RECORD_LEN_FOR(S2N_MIN_SEND_BUFFER_FRAGMENT_SIZE), S2N_ERR_INVALID_ARGUMENT);
POSIX_ENSURE(size >= S2N_MIN_SEND_BUFFER_SIZE, S2N_ERR_INVALID_ARGUMENT);
config->send_buffer_size_override = size;
return S2N_SUCCESS;
}
Expand Down
2 changes: 2 additions & 0 deletions tls/s2n_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "crypto/s2n_certificate.h"
#include "crypto/s2n_dhe.h"
#include "tls/s2n_crl.h"
#include "tls/s2n_record.h"
#include "tls/s2n_key_update.h"
#include "tls/s2n_psk.h"
#include "tls/s2n_renegotiate.h"
Expand All @@ -43,6 +44,7 @@
* The send buffer must be able to hold an unfragmented KeyUpdate message.
*/
#define S2N_MIN_SEND_BUFFER_FRAGMENT_SIZE MAX(S2N_KEY_UPDATE_MESSAGE_SIZE, S2N_ALERT_LENGTH)
#define S2N_MIN_SEND_BUFFER_SIZE S2N_TLS_MAX_RECORD_LEN_FOR(S2N_MIN_SEND_BUFFER_FRAGMENT_SIZE)

struct s2n_cipher_preferences;

Expand Down

0 comments on commit 0455969

Please sign in to comment.