s2n-tls icon indicating copy to clipboard operation
s2n-tls copied to clipboard

s2n_stuffer_skip_write usage pattern

Open baldwinmatt opened this issue 4 years ago • 4 comments

Problem:

A common pattern is:

GUARD(s2n_stuffer_skip_write(stuffer, bytes_to_write));
uint8_t* ptr = suffer->blob.data + stuffer->write_cursor - bytes_to_write;

which could be simplified.

Solution:

*ptr could be an *out parameter to s2n_stuffer_skip_write

  • Does this change what S2N sends over the wire? No.
  • Does this change any public APIs? No.
  • Which versions of TLS will this impact? N/A.

Requirements / Acceptance Criteria:

What must a solution address in order to solve the problem? How do we know the solution is complete?

  • Testing: Existing tests should pass as is, however CBMC proofs will need to be updated to match thew new stuffer API
    • Will this change trigger SAW changes? No.
    • Should this change be fuzz tested? N/A

Out of scope:

Is there anything the solution will intentionally NOT address?

No

baldwinmatt avatar Jun 26 '20 16:06 baldwinmatt

Actually, would it make sense for the skip_write to return a s2n_blob_slice, so we carry around both the size, and the pointer together? https://github.com/awslabs/s2n/blob/0e74e54a14c4f48f95ebcb24cffd6690d0c11e4d/utils/s2n_blob.c#L55

danielsn avatar Jun 26 '20 17:06 danielsn

Actually, would it make sense for the skip_write to return a s2n_blob_slice, so we carry around both the size, and the pointer together?

https://github.com/awslabs/s2n/blob/0e74e54a14c4f48f95ebcb24cffd6690d0c11e4d/utils/s2n_blob.c#L55

love it!

baldwinmatt avatar Jun 30 '20 02:06 baldwinmatt

i could find this pattern 2 times

3 times POSIX_GUARD(s2n_stuffer_skip_write(stuffer, length)); uint8_t *data = (stuffer->blob.data) ? (stuffer->blob.data + stuffer->write_cursor - length) : NULL;

and 32 cases where s2n_stuffer_skip_write is used in another context.

and 39 cases where s2n_stuffer_skip_write is being tested without use of this pattern

sneznaj avatar May 15 '22 02:05 sneznaj

Since this pattern occurs a minority of the time and is conceptually distinct, I propose to define a separate method to encapsulate this pattern: s2n_stuff_bypass_write(struct s2n_stuffer *stuffer, const uint32_t n, struct s2n_blob *bypassed_slice). Where bypassed_slice is a s2n_blob_slice as proposed by @danielsn.

We can pull out this common use case into a separate function without forcing the common use case to pass an output parameter. How does this sound?

zawie avatar Jul 23 '22 17:07 zawie

may i work on this issue and perform a PR? @danielsn @zawie

zakhaev26 avatar Apr 25 '23 15:04 zakhaev26