Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

s2n_stuffer should support read only semantics #4936

Open
jmayclin opened this issue Nov 26, 2024 · 0 comments
Open

s2n_stuffer should support read only semantics #4936

jmayclin opened this issue Nov 26, 2024 · 0 comments

Comments

@jmayclin
Copy link
Contributor

Problem:

The C pointer often take mutable pointers when the API is logically const.

This results in a large number unsafe casts in the Rust bindings. There are limited mechanisms to enforce that

  1. the statements were correct with the code was written
  2. the statements will remain correct as the code evolves.

This has already been discussed in #4140 .

Part of resolving this will require s2n_stuffers to support read-only behaviors.

struct s2n_stuffer* s = s2n_stuffer_from_ro_data(const uint8_t* data);

We already have methods for this purpose, but they serve more as documentation than enforcement.

int S2N_RESULT_MUST_USE s2n_stuffer_alloc_ro_from_string(struct s2n_stuffer *stuffer, const char *str);
int S2N_RESULT_MUST_USE s2n_stuffer_init_ro_from_string(struct s2n_stuffer *stuffer, uint8_t *data, uint32_t length);

Solution:

Any improvement is good. A solution does not have to be perfect to provide us with utility.

Correspondingly, s2n-tls should add runtime checks to the s2n_stuffer.

A bitflag writeable would be added to s2n_stuffer.

All methods that write to the data inside the stuffer would include a new check

RESULT_PRECONDITION(s2n_stuffer_is_writeable(s));

Standard stuffer initialization methods would set writeable to true. s2n_stuffer_init_ro_from_string would not set the writeable bit. This would make storing const data in s2n_stuffers much safer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants