1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545
|
[//]: # (DO NOT DIRECTLY MODIFY THIS FILE:)
[//]: # (The code in this file is generated from scripts/s2n_safety_macros.py and any modifications)
[//]: # (should be in there.)
# S2N Safety Macros
## Macros for functions that return `S2N_RESULT`
### RESULT_BAIL(error)
Sets the global `s2n_errno` to `error` and returns with an `S2N_RESULT_ERROR`
### RESULT_ENSURE(condition, error)
Ensures the `condition` is `true`, otherwise the function will `RESULT_BAIL` with `error`
### RESULT_DEBUG_ENSURE(condition, error)
Ensures the `condition` is `true`, otherwise the function will `RESULT_BAIL` with `error`
NOTE: The condition will _only_ be checked when the code is compiled in debug mode.
In release mode, the check is removed.
### RESULT_ENSURE_OK(result, error)
Ensures `s2n_result_is_ok(result)`, otherwise the function will `RESULT_BAIL` with `error`
This can be useful for overriding the global `s2n_errno`
### RESULT_ENSURE_GTE(a, b)
Ensures `a` is greater than or equal to `b`, otherwise the function will `RESULT_BAIL` with a `S2N_ERR_SAFETY` error
### RESULT_ENSURE_LTE(a, b)
Ensures `a` is less than or equal to `b`, otherwise the function will `RESULT_BAIL` with a `S2N_ERR_SAFETY` error
### RESULT_ENSURE_GT(a, b)
Ensures `a` is greater than `b`, otherwise the function will `RESULT_BAIL` with a `S2N_ERR_SAFETY` error
### RESULT_ENSURE_LT(a, b)
Ensures `a` is less than `b`, otherwise the function will `RESULT_BAIL` with a `S2N_ERR_SAFETY` error
### RESULT_ENSURE_EQ(a, b)
Ensures `a` is equal to `b`, otherwise the function will `RESULT_BAIL` with a `S2N_ERR_SAFETY` error
### RESULT_ENSURE_NE(a, b)
Ensures `a` is not equal to `b`, otherwise the function will `RESULT_BAIL` with a `S2N_ERR_SAFETY` error
### RESULT_ENSURE_INCLUSIVE_RANGE(min, n, max)
Ensures `min <= n <= max`, otherwise the function will `RESULT_BAIL` with `S2N_ERR_SAFETY`
### RESULT_ENSURE_EXCLUSIVE_RANGE(min, n, max)
Ensures `min < n < max`, otherwise the function will `RESULT_BAIL` with `S2N_ERR_SAFETY`
### RESULT_ENSURE_REF(x)
Ensures `x` is a readable reference, otherwise the function will `RESULT_BAIL` with `S2N_ERR_NULL`
### RESULT_ENSURE_MUT(x)
Ensures `x` is a mutable reference, otherwise the function will `RESULT_BAIL` with `S2N_ERR_NULL`
### RESULT_PRECONDITION(result)
Ensures the `result` is `S2N_RESULT_OK`, otherwise the function will return an error signal
`RESULT_PRECONDITION` should be used at the beginning of a function to make assertions about
the provided arguments. By default, it is functionally equivalent to `RESULT_GUARD(result)`
but can be altered by a testing environment to provide additional guarantees.
### RESULT_POSTCONDITION(result)
Ensures the `result` is `S2N_RESULT_OK`, otherwise the function will return an error signal
NOTE: The condition will _only_ be checked when the code is compiled in debug mode.
In release mode, the check is removed.
`RESULT_POSTCONDITION` should be used at the end of a function to make assertions about
the resulting state. In debug mode, it is functionally equivalent to `RESULT_GUARD(result)`.
In production builds, it becomes a no-op. This can also be altered by a testing environment
to provide additional guarantees.
### RESULT_CHECKED_MEMCPY(destination, source, len)
Performs a safer memcpy.
The following checks are performed:
* `destination` is non-null
* `source` is non-null
Callers will still need to ensure the following:
* The size of the data pointed to by both the `destination` and `source` parameters,
shall be at least `len` bytes.
### RESULT_CHECKED_MEMSET(destination, value, len)
Performs a safer memset
The following checks are performed:
* `destination` is non-null
Callers will still need to ensure the following:
* The size of the data pointed to by the `destination` parameter shall be at least
`len` bytes.
### RESULT_GUARD(result)
Ensures `s2n_result_is_ok(result)`, otherwise the function will return `S2N_RESULT_ERROR`
### RESULT_GUARD_OSSL(result, error)
Ensures `result == _OSSL_SUCCESS`, otherwise the function will `RESULT_BAIL` with `error`
### RESULT_GUARD_POSIX(result)
Ensures `(result) > S2N_FAILURE`, otherwise the function will return `S2N_RESULT_ERROR`
### RESULT_GUARD_PTR(result)
Ensures `(result) != NULL`, otherwise the function will return `S2N_RESULT_ERROR`
Does not set s2n_errno to S2N_ERR_NULL, so is NOT a direct replacement for RESULT_ENSURE_REF.
## Macros for functions that return `int` (POSIX error signal)
### POSIX_BAIL(error)
DEPRECATED: all methods (except those in s2n.h) should return s2n_result.
Sets the global `s2n_errno` to `error` and returns with an `S2N_FAILURE`
### POSIX_ENSURE(condition, error)
DEPRECATED: all methods (except those in s2n.h) should return s2n_result.
Ensures the `condition` is `true`, otherwise the function will `POSIX_BAIL` with `error`
### POSIX_DEBUG_ENSURE(condition, error)
DEPRECATED: all methods (except those in s2n.h) should return s2n_result.
Ensures the `condition` is `true`, otherwise the function will `POSIX_BAIL` with `error`
NOTE: The condition will _only_ be checked when the code is compiled in debug mode.
In release mode, the check is removed.
### POSIX_ENSURE_OK(result, error)
DEPRECATED: all methods (except those in s2n.h) should return s2n_result.
Ensures `(result) > S2N_FAILURE`, otherwise the function will `POSIX_BAIL` with `error`
This can be useful for overriding the global `s2n_errno`
### POSIX_ENSURE_GTE(a, b)
DEPRECATED: all methods (except those in s2n.h) should return s2n_result.
Ensures `a` is greater than or equal to `b`, otherwise the function will `POSIX_BAIL` with a `S2N_ERR_SAFETY` error
### POSIX_ENSURE_LTE(a, b)
DEPRECATED: all methods (except those in s2n.h) should return s2n_result.
Ensures `a` is less than or equal to `b`, otherwise the function will `POSIX_BAIL` with a `S2N_ERR_SAFETY` error
### POSIX_ENSURE_GT(a, b)
DEPRECATED: all methods (except those in s2n.h) should return s2n_result.
Ensures `a` is greater than `b`, otherwise the function will `POSIX_BAIL` with a `S2N_ERR_SAFETY` error
### POSIX_ENSURE_LT(a, b)
DEPRECATED: all methods (except those in s2n.h) should return s2n_result.
Ensures `a` is less than `b`, otherwise the function will `POSIX_BAIL` with a `S2N_ERR_SAFETY` error
### POSIX_ENSURE_EQ(a, b)
DEPRECATED: all methods (except those in s2n.h) should return s2n_result.
Ensures `a` is equal to `b`, otherwise the function will `POSIX_BAIL` with a `S2N_ERR_SAFETY` error
### POSIX_ENSURE_NE(a, b)
DEPRECATED: all methods (except those in s2n.h) should return s2n_result.
Ensures `a` is not equal to `b`, otherwise the function will `POSIX_BAIL` with a `S2N_ERR_SAFETY` error
### POSIX_ENSURE_INCLUSIVE_RANGE(min, n, max)
DEPRECATED: all methods (except those in s2n.h) should return s2n_result.
Ensures `min <= n <= max`, otherwise the function will `POSIX_BAIL` with `S2N_ERR_SAFETY`
### POSIX_ENSURE_EXCLUSIVE_RANGE(min, n, max)
DEPRECATED: all methods (except those in s2n.h) should return s2n_result.
Ensures `min < n < max`, otherwise the function will `POSIX_BAIL` with `S2N_ERR_SAFETY`
### POSIX_ENSURE_REF(x)
DEPRECATED: all methods (except those in s2n.h) should return s2n_result.
Ensures `x` is a readable reference, otherwise the function will `POSIX_BAIL` with `S2N_ERR_NULL`
### POSIX_ENSURE_MUT(x)
DEPRECATED: all methods (except those in s2n.h) should return s2n_result.
Ensures `x` is a mutable reference, otherwise the function will `POSIX_BAIL` with `S2N_ERR_NULL`
### POSIX_PRECONDITION(result)
DEPRECATED: all methods (except those in s2n.h) should return s2n_result.
Ensures the `result` is `S2N_RESULT_OK`, otherwise the function will return an error signal
`POSIX_PRECONDITION` should be used at the beginning of a function to make assertions about
the provided arguments. By default, it is functionally equivalent to `POSIX_GUARD_RESULT(result)`
but can be altered by a testing environment to provide additional guarantees.
### POSIX_POSTCONDITION(result)
DEPRECATED: all methods (except those in s2n.h) should return s2n_result.
Ensures the `result` is `S2N_RESULT_OK`, otherwise the function will return an error signal
NOTE: The condition will _only_ be checked when the code is compiled in debug mode.
In release mode, the check is removed.
`POSIX_POSTCONDITION` should be used at the end of a function to make assertions about
the resulting state. In debug mode, it is functionally equivalent to `POSIX_GUARD_RESULT(result)`.
In production builds, it becomes a no-op. This can also be altered by a testing environment
to provide additional guarantees.
### POSIX_CHECKED_MEMCPY(destination, source, len)
DEPRECATED: all methods (except those in s2n.h) should return s2n_result.
Performs a safer memcpy.
The following checks are performed:
* `destination` is non-null
* `source` is non-null
Callers will still need to ensure the following:
* The size of the data pointed to by both the `destination` and `source` parameters,
shall be at least `len` bytes.
### POSIX_CHECKED_MEMSET(destination, value, len)
DEPRECATED: all methods (except those in s2n.h) should return s2n_result.
Performs a safer memset
The following checks are performed:
* `destination` is non-null
Callers will still need to ensure the following:
* The size of the data pointed to by the `destination` parameter shall be at least
`len` bytes.
### POSIX_GUARD(result)
DEPRECATED: all methods (except those in s2n.h) should return s2n_result.
Ensures `(result) > S2N_FAILURE`, otherwise the function will return `S2N_FAILURE`
### POSIX_GUARD_OSSL(result, error)
DEPRECATED: all methods (except those in s2n.h) should return s2n_result.
Ensures `result == _OSSL_SUCCESS`, otherwise the function will `POSIX_BAIL` with `error`
### POSIX_GUARD_RESULT(result)
DEPRECATED: all methods (except those in s2n.h) should return s2n_result.
Ensures `s2n_result_is_ok(result)`, otherwise the function will return `S2N_FAILURE`
### POSIX_GUARD_PTR(result)
DEPRECATED: all methods (except those in s2n.h) should return s2n_result.
Ensures `(result) != NULL`, otherwise the function will return `S2N_FAILURE`
Does not set s2n_errno to S2N_ERR_NULL, so is NOT a direct replacement for POSIX_ENSURE_REF.
## Macros for functions that return a pointer
### PTR_BAIL(error)
DEPRECATED: all methods (except those in s2n.h) should return s2n_result.
Sets the global `s2n_errno` to `error` and returns with an `NULL`
### PTR_ENSURE(condition, error)
DEPRECATED: all methods (except those in s2n.h) should return s2n_result.
Ensures the `condition` is `true`, otherwise the function will `PTR_BAIL` with `error`
### PTR_DEBUG_ENSURE(condition, error)
DEPRECATED: all methods (except those in s2n.h) should return s2n_result.
Ensures the `condition` is `true`, otherwise the function will `PTR_BAIL` with `error`
NOTE: The condition will _only_ be checked when the code is compiled in debug mode.
In release mode, the check is removed.
### PTR_ENSURE_OK(result, error)
DEPRECATED: all methods (except those in s2n.h) should return s2n_result.
Ensures `(result) != NULL`, otherwise the function will `PTR_BAIL` with `error`
This can be useful for overriding the global `s2n_errno`
### PTR_ENSURE_GTE(a, b)
DEPRECATED: all methods (except those in s2n.h) should return s2n_result.
Ensures `a` is greater than or equal to `b`, otherwise the function will `PTR_BAIL` with a `S2N_ERR_SAFETY` error
### PTR_ENSURE_LTE(a, b)
DEPRECATED: all methods (except those in s2n.h) should return s2n_result.
Ensures `a` is less than or equal to `b`, otherwise the function will `PTR_BAIL` with a `S2N_ERR_SAFETY` error
### PTR_ENSURE_GT(a, b)
DEPRECATED: all methods (except those in s2n.h) should return s2n_result.
Ensures `a` is greater than `b`, otherwise the function will `PTR_BAIL` with a `S2N_ERR_SAFETY` error
### PTR_ENSURE_LT(a, b)
DEPRECATED: all methods (except those in s2n.h) should return s2n_result.
Ensures `a` is less than `b`, otherwise the function will `PTR_BAIL` with a `S2N_ERR_SAFETY` error
### PTR_ENSURE_EQ(a, b)
DEPRECATED: all methods (except those in s2n.h) should return s2n_result.
Ensures `a` is equal to `b`, otherwise the function will `PTR_BAIL` with a `S2N_ERR_SAFETY` error
### PTR_ENSURE_NE(a, b)
DEPRECATED: all methods (except those in s2n.h) should return s2n_result.
Ensures `a` is not equal to `b`, otherwise the function will `PTR_BAIL` with a `S2N_ERR_SAFETY` error
### PTR_ENSURE_INCLUSIVE_RANGE(min, n, max)
DEPRECATED: all methods (except those in s2n.h) should return s2n_result.
Ensures `min <= n <= max`, otherwise the function will `PTR_BAIL` with `S2N_ERR_SAFETY`
### PTR_ENSURE_EXCLUSIVE_RANGE(min, n, max)
DEPRECATED: all methods (except those in s2n.h) should return s2n_result.
Ensures `min < n < max`, otherwise the function will `PTR_BAIL` with `S2N_ERR_SAFETY`
### PTR_ENSURE_REF(x)
DEPRECATED: all methods (except those in s2n.h) should return s2n_result.
Ensures `x` is a readable reference, otherwise the function will `PTR_BAIL` with `S2N_ERR_NULL`
### PTR_ENSURE_MUT(x)
DEPRECATED: all methods (except those in s2n.h) should return s2n_result.
Ensures `x` is a mutable reference, otherwise the function will `PTR_BAIL` with `S2N_ERR_NULL`
### PTR_PRECONDITION(result)
DEPRECATED: all methods (except those in s2n.h) should return s2n_result.
Ensures the `result` is `S2N_RESULT_OK`, otherwise the function will return an error signal
`PTR_PRECONDITION` should be used at the beginning of a function to make assertions about
the provided arguments. By default, it is functionally equivalent to `PTR_GUARD_RESULT(result)`
but can be altered by a testing environment to provide additional guarantees.
### PTR_POSTCONDITION(result)
DEPRECATED: all methods (except those in s2n.h) should return s2n_result.
Ensures the `result` is `S2N_RESULT_OK`, otherwise the function will return an error signal
NOTE: The condition will _only_ be checked when the code is compiled in debug mode.
In release mode, the check is removed.
`PTR_POSTCONDITION` should be used at the end of a function to make assertions about
the resulting state. In debug mode, it is functionally equivalent to `PTR_GUARD_RESULT(result)`.
In production builds, it becomes a no-op. This can also be altered by a testing environment
to provide additional guarantees.
### PTR_CHECKED_MEMCPY(destination, source, len)
DEPRECATED: all methods (except those in s2n.h) should return s2n_result.
Performs a safer memcpy.
The following checks are performed:
* `destination` is non-null
* `source` is non-null
Callers will still need to ensure the following:
* The size of the data pointed to by both the `destination` and `source` parameters,
shall be at least `len` bytes.
### PTR_CHECKED_MEMSET(destination, value, len)
DEPRECATED: all methods (except those in s2n.h) should return s2n_result.
Performs a safer memset
The following checks are performed:
* `destination` is non-null
Callers will still need to ensure the following:
* The size of the data pointed to by the `destination` parameter shall be at least
`len` bytes.
### PTR_GUARD(result)
DEPRECATED: all methods (except those in s2n.h) should return s2n_result.
Ensures `(result) != NULL`, otherwise the function will return `NULL`
### PTR_GUARD_OSSL(result, error)
DEPRECATED: all methods (except those in s2n.h) should return s2n_result.
Ensures `result == _OSSL_SUCCESS`, otherwise the function will `PTR_BAIL` with `error`
### PTR_GUARD_RESULT(result)
DEPRECATED: all methods (except those in s2n.h) should return s2n_result.
Ensures `s2n_result_is_ok(result)`, otherwise the function will return `NULL`
### PTR_GUARD_POSIX(result)
DEPRECATED: all methods (except those in s2n.h) should return s2n_result.
Ensures `(result) > S2N_FAILURE`, otherwise the function will return `NULL`
|