refactor(ffi): check pointer arguments for NULL (#2624)

This changes all the extern C functions in `hyper::ffi` to check passed
pointer arguments for being `NULL` before trying to use them. Before, we
would just assume the programmer had passed a good pointer, which could
result in segmentation faults. Now:

- In debug builds, it will assert they aren't null, and so if they are,
  a message identifying the argument name will be printed and then the
  process will crash.
- In release builds, it will still check for null, but if found, it will
  return early, with a return value indicating failure if the return type
  allows (such as returning NULL, or `HYPERE_INVALID_ARG`).

Closes #2620
This commit is contained in:
Sean McArthur
2021-08-18 14:15:14 -07:00
committed by GitHub
parent c35153998e
commit 3b26572876
8 changed files with 85 additions and 93 deletions

View File

@@ -153,8 +153,10 @@ static void print_informational(void *userdata, const hyper_response *resp) {
printf("\nInformational (1xx): %d\n", http_status);
const hyper_buf* headers = hyper_response_headers_raw(resp);
write(1, hyper_buf_bytes(headers), hyper_buf_len(headers));
const hyper_buf *headers = hyper_response_headers_raw(resp);
if (headers) {
write(1, hyper_buf_bytes(headers), hyper_buf_len(headers));
}
}
typedef enum {