mike-jumper opened a new pull request, #462:
URL: https://github.com/apache/guacamole-server/pull/462
This change adds several convenience functions for management of memory,
each analogous to standard functions but with the added benefits of checked
arithmetic and automatic `NULL`-ing of freed pointers:
Standard function | libguac function
------------------ | ----------------
`malloc()` | `guac_mem_alloc()`
`calloc()` | `guac_mem_zalloc()`
`free()` | `guac_mem_free()`
Additional functions are provided for performing arithmetic prior to
allocating memory, as is often necessary in more complex cases. These functions
are based off the C23 standard draft that includes new macros for checked
arithmetic:
* `guac_mem_ckd_mul()` - Multiplies a series of `size_t` integers together,
storing the result in a provided `size_t` variable and returning whether
overflow occurred.
* `guac_mem_ckd_add()` - Adds a series of `size_t` integers together,
storing the result in a provided `size_t` variable and returning whether
overflow occurred.
* `guac_mem_ckd_sub()` - Subtracts a series of `size_t` integers from each
other, storing the result in a provided `size_t` variable and returning whether
overflow occurred (NOTE: this is necessary vs. simply adding negative values as
`size_t` is an unsigned type).
As it's often inconvenient to repeatedly store intermediate results,
`*_or_die()` variants of the above are also provided. Each of these is
identical in behavior to the original, except that they will `abort()` the
entire process in the event of overflow:
* `guac_mem_ckd_mul_or_die()`
* `guac_mem_ckd_add_or_die()`
* `guac_mem_ckd_sub_or_die()`
There will definitely be conflicts against `master` after merge, but I think
these are pretty nifty and a step in the right direction in terms of
cleanliness and inherent safeguards / hardening. While the set of changes
itself is large, the changes themselves are mostly documentation, unit tests,
and trivial replacements.
(Opening as a draft for now while doing at least a quick smoke test of each
protocol...)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]