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

Migrate codebase to use S2N_RESULT by default #2425

Open
7 of 11 tasks
camshaft opened this issue Nov 30, 2020 · 1 comment
Open
7 of 11 tasks

Migrate codebase to use S2N_RESULT by default #2425

camshaft opened this issue Nov 30, 2020 · 1 comment

Comments

@camshaft
Copy link
Contributor

camshaft commented Nov 30, 2020

Problem:

Right now, most of the codebase uses int as the function return value. As documented in s2n_result.c, this has a few problems:

  • GUARDing in a function that returns integer types
  • GUARDing a function that returns integer type
  • Forgetting to GUARD a function that returned an error signal

Solution:

The majority of the codebase should return S2N_RESULT. This is statically checked to ensure:

  • The code cannot GUARD in a function that returns integer types:

    uint8_t s2n_answer_to_the_ultimate_question() {
      GUARD(s2n_sleep_for_years(7500000)); /* <- Won't compile since this function doesn't return an S2N_RESULT */
      return 42;
    }
  • The code cannot GUARD a function that returns integer types:

    S2N_RESULT s2n_deep_thought() {
      GUARD(s2n_answer_to_the_ultimate_question()); /* <- Won't compile since the function being called doesn't return an S2N_RESULT */
      return S2N_RESULT_OK;
    }
  • The code cannot ignore the return value of a function

    uint8_t s2n_answer_to_the_ultimate_question() {
      s2n_sleep_for_years(7500000); /* <- Won't compile since the function being called returns a `S2N_RESULT` isn't `GUARD`ed */
      return 42;
    }

Requirements / Acceptance Criteria:

The following tasks are implemented in a way that will make the transition as painless as possible, especially for any pending PRs.

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

3 participants
@camshaft @dougch and others