fort_SOURCES = main.c
fort_SOURCES += algorithm.h algorithm.c
+fort_SOURCES += alloc.h alloc.c
fort_SOURCES += certificate_refs.h certificate_refs.c
fort_SOURCES += cert_stack.h cert_stack.c
fort_SOURCES += common.c common.h
--- /dev/null
+#include "alloc.h"
+
+#include <string.h>
+#include "log.h"
+
+void *
+pmalloc(size_t size)
+{
+ void *result;
+
+ result = malloc(size);
+ if (result == NULL)
+ enomem_panic();
+
+ return result;
+}
+
+void *
+pzalloc(size_t size)
+{
+ void *result;
+
+ result = pmalloc(size);
+ memset(result, 0, size);
+
+ return result;
+}
+
+void *
+pcalloc(size_t nmemb, size_t size)
+{
+ void *result;
+
+ result = calloc(nmemb, size);
+ if (result == NULL)
+ enomem_panic();
+
+ return result;
+}
+
+void *
+prealloc(void *ptr, size_t size)
+{
+ void *result;
+
+ result = realloc(ptr, size);
+ if (result == NULL)
+ enomem_panic();
+
+ return result;
+}
+
+void *
+pmclone(void const *src, size_t size)
+{
+ void *result;
+
+ result = pmalloc(size);
+ if (result == NULL)
+ enomem_panic();
+ memcpy(result, src, size);
+
+ return result;
+}
+
+char *
+pstrdup(const char *s)
+{
+ char *result;
+
+ result = strdup(s);
+ if (result == NULL)
+ enomem_panic();
+
+ return result;
+}
--- /dev/null
+#ifndef SRC_ALLOC_H_
+#define SRC_ALLOC_H_
+
+#include <stdlib.h>
+
+/* malloc(), but panic on allocation failure. */
+void *pmalloc(size_t size);
+/* malloc(), but panic on allocation failure, zeroize memory on success. */
+void *pzalloc(size_t size);
+/* calloc(), but panic on allocation failure. */
+void *pcalloc(size_t nmemb, size_t size);
+/* realloc(), but panic on allocation failure. */
+void *prealloc(void *ptr, size_t size);
+/* Clone @src on the heap, panic on allocation failure. */
+void *pmclone(void const *src, size_t size);
+
+/* strdup(), but panic on allocation failure. */
+char *pstrdup(char const *s);
+
+#endif /* SRC_ALLOC_H_ */
#include "oid.h"
#include <errno.h>
+#include "alloc.h"
#include "common.h"
#include "log.h"
#include "asn1/decode.h"
static const size_t MAX_ARCS = 9;
ssize_t count;
ssize_t count2;
- asn_oid_arc_t *tmp;
- result->arcs = malloc(MAX_ARCS * sizeof(asn_oid_arc_t));
- if (result->arcs == NULL)
- enomem_panic();
+ result->arcs = pmalloc(MAX_ARCS * sizeof(asn_oid_arc_t));
count = OBJECT_IDENTIFIER_get_arcs(oid, result->arcs, MAX_ARCS);
if (count < 0) {
/* If necessary, reallocate arcs array and try again. */
if (count > MAX_ARCS) {
- tmp = realloc(result->arcs, count * sizeof(asn_oid_arc_t));
- if (tmp == NULL)
- enomem_panic();
- result->arcs = tmp;
+ result->arcs = prealloc(result->arcs,
+ count * sizeof(asn_oid_arc_t));
count2 = OBJECT_IDENTIFIER_get_arcs(oid, result->arcs, count);
if (count != count2) {
#include <errno.h>
#include "algorithm.h"
+#include "alloc.h"
#include "config.h"
#include "log.h"
#include "oid.h"
if (error)
return error;
- sdata = calloc(1, sizeof(struct SignedData));
- if (sdata == NULL)
- enomem_panic();
+ sdata = pcalloc(1, sizeof(struct SignedData));
/* Parse content as OCTET STRING */
error = asn1_decode_any(sdata_pkcs7->encapContentInfo.eContent,
#include <sys/queue.h>
+#include "alloc.h"
#include "resource.h"
#include "str_token.h"
#include "thread_var.h"
{
struct cert_stack *stack;
- stack = malloc(sizeof(struct cert_stack));
- if (stack == NULL)
- enomem_panic();
+ stack = pmalloc(sizeof(struct cert_stack));
stack->x509s = sk_X509_new_null();
if (stack->x509s == NULL) {
{
struct defer_node *node;
- node = malloc(sizeof(struct defer_node));
- if (node == NULL)
- enomem_panic();
+ node = pmalloc(sizeof(struct defer_node));
node->type = DNT_CERT;
node->deferred = *deferred;
{
struct defer_node *result;
- result = malloc(sizeof(struct defer_node));
- if (result == NULL)
- enomem_panic();
-
+ result = pmalloc(sizeof(struct defer_node));
result->type = DNT_SEPARATOR;
+
return result;
}
int ok;
int error;
- meta = malloc(sizeof(struct metadata_node));
- if (meta == NULL)
- enomem_panic();
+ meta = pmalloc(sizeof(struct metadata_node));
meta->uri = uri;
uri_refget(uri);
get_current_file_name(void)
{
char const *file_name;
- char *result;
file_name = fnstack_peek();
if (file_name == NULL)
pr_crit("The file name stack is empty.");
- result = strdup(file_name);
- if (result == NULL)
- enomem_panic();
-
- return result;
+ return pstrdup(file_name);
}
/**
#include <dirent.h> /* readdir(), closedir() */
#include <limits.h> /* realpath() */
-#include <stdlib.h> /* malloc(), free(), realloc(), realpath() */
+#include <stdlib.h> /* free(), realpath() */
#include <stdio.h> /* remove() */
-#include <string.h> /* strdup(), strrchr(), strcmp(), strcat(), etc */
+#include <string.h> /* strrchr(), strcmp(), strcat(), etc */
#include <unistd.h> /* stat(), rmdir() */
#include <sys/stat.h> /* stat(), mkdir() */
#include <sys/types.h> /* stat(), closedir(), mkdir() */
+#include "alloc.h"
#include "config.h"
#include "log.h"
(*fcount)++; /* Increment the found count */
/* Get the full file path */
- tmp = strdup(dir_name);
- if (tmp == NULL)
- enomem_panic();
-
- tmp = realloc(tmp, strlen(tmp) + 1 + strlen(file_name) + 1);
- if (tmp == NULL)
- enomem_panic();
+ tmp = pstrdup(dir_name);
+ tmp = prealloc(tmp, strlen(tmp) + 1 + strlen(file_name) + 1);
strcat(tmp, "/");
strcat(tmp, file_name);
if (exist)
return 0;
- localuri = strdup(path);
- if (localuri == NULL)
- enomem_panic();
+ localuri = pstrdup(path);
for (i = 1; localuri[i] != '\0'; i++) {
if (localuri[i] == '/') {
if (error)
return error;
- config_repo = strdup(config_get_local_repository());
- if (config_repo == NULL)
- enomem_panic();
+ config_repo = pstrdup(config_get_local_repository());
/* Stop dir removal when the work_dir has this length */
config_len = strlen(config_repo);
config_len--;
free(config_repo);
- work_loc = strdup(path);
- if (work_loc == NULL)
- enomem_panic();
+ work_loc = pstrdup(path);
do {
tmp = strrchr(work_loc, '/');
if (workspace != NULL)
workspace_len = strlen(workspace);
- local = malloc(repository_len + extra_slash + workspace_len + uri_len + 1);
- if (local == NULL)
- enomem_panic();
+ local = pmalloc(repository_len + extra_slash + workspace_len + uri_len + 1);
offset = 0;
strcpy(local + offset, repository);
#include <sys/socket.h>
#include <syslog.h>
+#include "alloc.h"
#include "common.h"
#include "configure_ac.h"
#include "daemon.h"
}
/* +1 NULL end, means end of array. */
- long_opts = calloc(total_long_options + 1, sizeof(struct option));
- if (long_opts == NULL)
- enomem_panic();
- short_opts = malloc(total_short_options + 1);
- if (short_opts == NULL)
- enomem_panic();
+ long_opts = pcalloc(total_long_options + 1, sizeof(struct option));
+ short_opts = pmalloc(total_short_options + 1);
*_long_opts = long_opts;
*_short_opts = short_opts;
*/
string_array_init(&rpki_config.server.address, NULL, 0);
-
- rpki_config.server.port = strdup("323");
- if (rpki_config.server.port == NULL)
- enomem_panic();
-
+ rpki_config.server.port = pstrdup("323");
rpki_config.server.backlog = SOMAXCONN;
rpki_config.server.interval.validation = 3600;
rpki_config.server.interval.refresh = 3600;
rpki_config.server.deltas_lifetime = 2;
rpki_config.tal = NULL;
- rpki_config.slurm = NULL;
-
- rpki_config.local_repository = strdup("/tmp/fort/repository");
- if (rpki_config.local_repository == NULL)
- enomem_panic();
-
+ rpki_config.local_repository = pstrdup("/tmp/fort/repository");
rpki_config.sync_strategy = RSYNC_ROOT_EXCEPT_TA;
rpki_config.shuffle_tal_uris = false;
rpki_config.maximum_certificate_depth = 32;
+ rpki_config.slurm = NULL;
rpki_config.mode = SERVER;
rpki_config.work_offline = false;
rpki_config.daemon = false;
rpki_config.rsync.strategy = RSYNC_ROOT_EXCEPT_TA;
rpki_config.rsync.retry.count = 1;
rpki_config.rsync.retry.interval = 4;
- rpki_config.rsync.program = strdup("rsync");
- if (rpki_config.rsync.program == NULL)
- enomem_panic();
-
- string_array_init(&rpki_config.rsync.args.recursive,
- recursive_rsync_args, ARRAY_LEN(recursive_rsync_args));
+ rpki_config.rsync.program = pstrdup("rsync");
string_array_init(&rpki_config.rsync.args.flat,
flat_rsync_args, ARRAY_LEN(flat_rsync_args));
+ string_array_init(&rpki_config.rsync.args.recursive,
+ recursive_rsync_args, ARRAY_LEN(recursive_rsync_args));
/* By default, has a higher priority than rsync */
rpki_config.http.enabled = true;
rpki_config.http.priority = 60;
rpki_config.http.retry.count = 1;
rpki_config.http.retry.interval = 4;
- rpki_config.http.user_agent = strdup(PACKAGE_NAME "/" PACKAGE_VERSION);
- if (rpki_config.http.user_agent == NULL)
- enomem_panic();
+ rpki_config.http.user_agent = pstrdup(PACKAGE_NAME "/" PACKAGE_VERSION);
rpki_config.http.connect_timeout = 30;
rpki_config.http.transfer_timeout = 0;
rpki_config.http.low_speed_limit = 100000;
rpki_config.rrdp.retry.count = rpki_config.http.retry.count;
rpki_config.rrdp.retry.interval = rpki_config.http.retry.interval;
+ rpki_config.log.enabled = true;
+ rpki_config.log.tag = NULL;
rpki_config.log.color = false;
rpki_config.log.filename_format = FNF_GLOBAL;
rpki_config.log.level = LOG_WARNING;
rpki_config.log.output = CONSOLE;
-
- rpki_config.log.enabled = true;
- rpki_config.log.output = CONSOLE;
- rpki_config.log.level = LOG_WARNING;
- rpki_config.log.color = false;
- rpki_config.log.filename_format = FNF_GLOBAL;
rpki_config.log.facility = LOG_DAEMON;
- rpki_config.log.tag = NULL;
rpki_config.validation_log.enabled = false;
- rpki_config.validation_log.output = CONSOLE;
- rpki_config.validation_log.level = LOG_WARNING;
+ rpki_config.validation_log.tag = pstrdup("Validation");
rpki_config.validation_log.color = false;
rpki_config.validation_log.filename_format = FNF_GLOBAL;
+ rpki_config.validation_log.level = LOG_WARNING;
+ rpki_config.validation_log.output = CONSOLE;
rpki_config.validation_log.facility = LOG_DAEMON;
- rpki_config.validation_log.tag = strdup("Validation");
- if (rpki_config.validation_log.tag == NULL)
- enomem_panic();
rpki_config.output.roa = NULL;
rpki_config.output.bgpsec = NULL;
rpki_config.asn1_decode_max_stack = 4096; /* 4kB */
rpki_config.stale_repository_period = 43200; /* 12 hours */
-
rpki_config.init_tals = false;
rpki_config.init_tal_locations = 0;
- /* Common scenario is to connect 1 router or a couple of them */
rpki_config.thread_pool.server.max = 20;
- /* Usually 5 TALs, let a few more available */
rpki_config.thread_pool.validation.max = 5;
}
#include <getopt.h>
#include <stdlib.h>
#include <string.h>
+
+#include "alloc.h"
#include "log.h"
#define DEREFERENCE(void_value) (*((char **) void_value))
/* Remove the previous value (usually the default). */
__string_free(result);
- DEREFERENCE(result) = strdup(str);
- if (DEREFERENCE(result) == NULL)
- enomem_panic();
-
+ DEREFERENCE(result) = pstrdup(str);
return 0;
}
#include <stdlib.h>
#include <string.h>
+#include "alloc.h"
#include "log.h"
#include "str_token.h"
#include "config/str.h"
return;
}
- array->array = calloc(len, sizeof(char *));
- if (array->array == NULL)
- enomem_panic();
-
- for (i = 0; i < len; i++) {
- array->array[i] = strdup(values[i]);
- if (array->array[i] == NULL) {
- string_array_cleanup(array);
- enomem_panic();
- }
- }
+ array->array = pcalloc(len, sizeof(char *));
+ for (i = 0; i < len; i++)
+ array->array[i] = pstrdup(values[i]);
}
void
/* Remove the previous value (usually the default). */
__string_array_free(result);
- result->array = calloc(len, sizeof(char *));
- if (result->array == NULL)
- enomem_panic();
+ result->array = pcalloc(len, sizeof(char *));
result->length = len;
for (i = 0; i < len; i++) {
if (error)
goto fail;
- result->array[i] = strdup(tmp);
- if (result->array[i] == NULL)
- enomem_panic();
+ result->array[i] = pstrdup(tmp);
}
return 0;
return pr_op_err("'%s' can have %u elements max; currently it has %lu elements.",
opt->name, opt->max, len);
- result->array = calloc(len, sizeof(char *));
- if (result->array == NULL)
- enomem_panic();
+ result->array = pcalloc(len, sizeof(char *));
result->length = len;
for (i = 0; string_tokenizer_next(&tokenizer); i++)
#include <openssl/buffer.h>
#include <errno.h>
#include <string.h>
+#include "alloc.h"
#include "log.h"
/**
encoded_len = strlen(str_encoded);
pad = (encoded_len % 4) > 0 ? 4 - (encoded_len % 4) : 0;
- str_copy = malloc(encoded_len + pad + 1);
- if (str_copy == NULL)
- enomem_panic();
+ str_copy = pmalloc(encoded_len + pad + 1);
/* Set all with pad char, then replace with the original string */
memset(str_copy, '=', encoded_len + pad);
memcpy(str_copy, str_encoded, encoded_len);
}
alloc_size = EVP_DECODE_LENGTH(strlen(str_copy));
- *result = malloc(alloc_size + 1);
- if (*result == NULL)
- enomem_panic();
- memset(*result, 0, alloc_size);
- (*result)[alloc_size] = '\0';
+ *result = pzalloc(alloc_size + 1);
error = base64_decode(encoded, *result, false, alloc_size, &dec_len);
if (error)
len = pad - base;
} while(0);
- tmp = malloc(len + 1);
- if (tmp == NULL)
- enomem_panic();
-
+ tmp = pmalloc(len + 1);
memcpy(tmp, base, len);
tmp[len] = '\0';
#include <sys/stat.h>
#include <sys/types.h> /* For blksize_t */
+#include "alloc.h"
#include "common.h"
#include "file.h"
#include "log.h"
}
static int
-hash_file(char const *algorithm, struct rpki_uri *uri, unsigned char *result,
- unsigned int *result_len)
+hash_file(struct rpki_uri *uri, unsigned char *result, unsigned int *result_len)
{
- return hash_local_file(algorithm, uri_get_local(uri), result,
- result_len);
+ return hash_local_file(uri_get_local(uri), result, result_len);
}
int
-hash_local_file(char const *algorithm, char const *uri, unsigned char *result,
+hash_local_file(char const *uri, unsigned char *result,
unsigned int *result_len)
{
EVP_MD const *md;
FILE *file;
struct stat stat;
unsigned char *buffer;
- blksize_t buffer_len;
size_t consumed;
EVP_MD_CTX *ctx;
int error;
- error = get_md(algorithm, &md);
+ error = get_md("sha256", &md);
if (error)
return error;
if (error)
return error;
- buffer_len = stat.st_blksize;
- buffer = malloc(buffer_len);
- if (buffer == NULL)
- enomem_panic();
+ buffer = pmalloc(stat.st_blksize);
ctx = EVP_MD_CTX_new();
if (ctx == NULL)
}
do {
- consumed = fread(buffer, 1, buffer_len, file);
+ consumed = fread(buffer, 1, stat.st_blksize, file);
error = ferror(file);
if (error) {
pr_val_err("File reading error. Error message (apparently): %s",
* an incidence to ignore this).
*/
int
-hash_validate_mft_file(char const *algorithm, struct rpki_uri *uri,
- BIT_STRING_t const *expected)
+hash_validate_mft_file(struct rpki_uri *uri, BIT_STRING_t const *expected)
{
unsigned char actual[EVP_MAX_MD_SIZE];
unsigned int actual_len;
return pr_val_err("Hash string has unused bits.");
do {
- error = hash_file(algorithm, uri, actual, &actual_len);
+ error = hash_file(uri, actual, &actual_len);
if (!error)
break;
* @expected_len. Returns 0 if no errors happened and the hashes match.
*/
int
-hash_validate_file(char const *algorithm, struct rpki_uri *uri,
- unsigned char const *expected, size_t expected_len)
+hash_validate_file(struct rpki_uri *uri, unsigned char const *expected,
+ size_t expected_len)
{
unsigned char actual[EVP_MAX_MD_SIZE];
unsigned int actual_len;
int error;
- error = hash_file(algorithm, uri, actual, &actual_len);
+ error = hash_file(uri, actual, &actual_len);
if (error)
return error;
hash_str(char const *algorithm, char const *str, unsigned char *result,
unsigned int *result_len)
{
- unsigned char *src;
- int error;
-
- src = malloc(strlen(str));
- if (src == NULL)
- enomem_panic();
-
- memcpy(src, str, strlen(str));
-
- error = hash_buffer(algorithm, src, strlen(str), result, result_len);
-
- free(src);
- return error;
+ return hash_buffer(algorithm, (unsigned char const *) str, strlen(str),
+ result, result_len);
}
#include "types/uri.h"
#include "asn1/asn1c/BIT_STRING.h"
-int hash_validate_mft_file(char const *, struct rpki_uri *uri,
- BIT_STRING_t const *);
-int hash_validate_file(char const *, struct rpki_uri *, unsigned char const *,
- size_t);
+int hash_validate_mft_file(struct rpki_uri *uri, BIT_STRING_t const *);
+int hash_validate_file(struct rpki_uri *, unsigned char const *, size_t);
int hash_validate(char const *, unsigned char const *, size_t,
unsigned char const *, size_t);
int hash_validate_octet_string(char const *, OCTET_STRING_t const*,
OCTET_STRING_t const *);
-int hash_local_file(char const *, char const *, unsigned char *,
- unsigned int *);
+int hash_local_file(char const *, unsigned char *, unsigned int *);
int hash_str(char const *, char const *, unsigned char *, unsigned int *);
#include <stdio.h>
#include <string.h>
#include <unistd.h>
+#include "alloc.h"
#include "common.h"
#include "internal_pool.h"
#include "log.h"
if (strrchr(local_path, '/') == local_path + strlen(local_path) - 1)
tmp_size--;
- tmp = malloc(tmp_size + 1);
- if (tmp == NULL)
- enomem_panic();
+ tmp = pmalloc(tmp_size + 1);
strncpy(tmp, local_path, tmp_size);
tmp[tmp_size] = '\0';
rcvd_size = strlen(rcvd);
/* original size + one underscore + hex random val (8 chars) */
tmp_size = rcvd_size + 1 + (sizeof(RAND_MAX) * 2);
- tmp = malloc(tmp_size + 1);
- if (tmp == NULL)
- enomem_panic();
+ tmp = pmalloc(tmp_size + 1);
/* Rename the path with a random suffix */
random_init();
{
struct rem_dirs *tmp;
- tmp = malloc(sizeof(struct rem_dirs));
- if (tmp == NULL)
- enomem_panic();
-
- tmp->arr = calloc(arr_len, sizeof(char *));
- if (tmp->arr == NULL)
- enomem_panic();
+ tmp = pmalloc(sizeof(struct rem_dirs));
+ tmp->arr = pcalloc(arr_len, sizeof(char *));
tmp->arr_len = arr_len;
tmp->arr_set = 0;
#include <errno.h>
#include <stdlib.h>
+
+#include "alloc.h"
#include "log.h"
static int
return error;
fc->buffer_size = stat.st_size;
- fc->buffer = malloc(fc->buffer_size);
- if (fc->buffer == NULL)
- enomem_panic();
+ fc->buffer = pmalloc(fc->buffer_size);
fread_result = fread(fc->buffer, 1, fc->buffer_size, file);
if (fread_result < fc->buffer_size) {
#include <stdio.h>
#include <unistd.h>
#include <curl/curl.h>
+
+#include "alloc.h"
#include "common.h"
#include "config.h"
#include "file.h"
original_file = uri_get_local(uri);
- tmp_file = malloc(strlen(original_file) + strlen(tmp_suffix) + 1);
- if (tmp_file == NULL)
- enomem_panic();
+ tmp_file = pmalloc(strlen(original_file) + strlen(tmp_suffix) + 1);
strcpy(tmp_file, original_file);
strcat(tmp_file, tmp_suffix);
FILE *out;
long response_code;
long cond_met;
- char *tmp_file, *tmp;
+ char *tmp_file;
int error;
- tmp_file = strdup(dest);
- if (tmp_file == NULL)
- enomem_panic();
-
- tmp = realloc(tmp_file, strlen(tmp_file) + strlen(tmp_suffix) + 1);
- if (tmp == NULL)
- enomem_panic();
-
- tmp_file = tmp;
+ tmp_file = pstrdup(dest);
+ tmp_file = prealloc(tmp_file, strlen(tmp_file) + strlen(tmp_suffix) + 1);
strcat(tmp_file, tmp_suffix);
error = file_write(tmp_file, &out);
#include <stdbool.h>
#include <unistd.h>
+#include "alloc.h"
#include "log.h"
#include "http/http.h"
extra_slash = (dest_dir[dest_dir_len - 1] == '/') ? 0 : 1;
- dest = malloc(dest_dir_len + extra_slash + strlen(dest_file) + 1);
- if (dest == NULL)
- enomem_panic();
+ dest = pmalloc(dest_dir_len + extra_slash + strlen(dest_file) + 1);
offset = 0;
strcpy(dest + offset, dest_dir);
#include <errno.h>
#include <string.h>
+#include "alloc.h"
#include "config.h"
#include "log.h"
#include "config/types.h"
struct json_t *node;
/* strtok_r() needs a non-const string */
- strtok.opt_name = strdup(full_name);
- if (strtok.opt_name == NULL)
- enomem_panic();
+ strtok.opt_name = pstrdup(full_name);
node = root;
strtok.token = strtok_r(strtok.opt_name, ".", &strtok.saveptr);
#include <errno.h>
#include <stdlib.h>
+#include "alloc.h"
#include "file.h"
#include "log.h"
struct line_file *lfile;
int error;
- lfile = malloc(sizeof(struct line_file));
- if (lfile == NULL)
- enomem_panic();
+ lfile = pmalloc(sizeof(struct line_file));
lfile->file = fopen(file_name, "r");
if (lfile->file == NULL) {
#include "bgpsec.h"
+#include "alloc.h"
#include "log.h"
#include "validation_handler.h"
if (pub_key == NULL)
return val_crypto_err("X509_get_X509_PUBKEY() returned NULL at BGPsec");
- cert_spk = malloc(RK_SPKI_LEN);
- if (cert_spk == NULL)
- enomem_panic();
+ cert_spk = pmalloc(RK_SPKI_LEN);
/* Use a temporal pointer, since i2d_X509_PUBKEY moves it */
tmp = cert_spk;
#include <sys/socket.h>
#include "algorithm.h"
+#include "alloc.h"
#include "config.h"
#include "extension.h"
#include "log.h"
}
}
- tmp = malloc(i + 1);
- if (tmp == NULL)
- enomem_panic();
-
+ tmp = pmalloc(i + 1);
strncpy(tmp, global, i);
tmp[i] = '\0';
* - Positive value: file doesn't exist and keep validating
* manifest.
*/
- error = hash_validate_mft_file("sha256", uri, &fah->hash);
+ error = hash_validate_mft_file(uri, &fah->hash);
if (error < 0) {
uri_refput(uri);
goto fail;
#include <string.h>
#include <syslog.h>
+#include "alloc.h"
#include "log.h"
#include "thread_var.h"
if (data == NULL)
return val_crypto_err("X509_NAME_ENTRY_get_data() returned NULL");
- result = malloc(data->length + 1);
- if (result == NULL)
- enomem_panic();
-
+ result = pmalloc(data->length + 1);
memcpy(result, data->data, data->length);
result[data->length] = '\0';
int nid;
int error;
- result = malloc(sizeof(struct rfc5280_name));
- if (result == NULL)
- enomem_panic();
+ result = pmalloc(sizeof(struct rfc5280_name));
result->commonName = NULL;
result->serialNumber = NULL;
#include <sys/stat.h>
#include <openssl/evp.h>
+#include "alloc.h"
#include "cert_stack.h"
#include "common.h"
#include "config.h"
uris->rsync_count = 0;
uris->https_count = 0;
uris->size = 4; /* Most TALs only define one. */
- uris->array = malloc(uris->size * sizeof(struct rpki_uri *));
- if (uris->array == NULL)
- enomem_panic();
+ uris->array = pmalloc(uris->size * sizeof(struct rpki_uri *));
}
static void
static int
uris_add(struct uris *uris, char *uri)
{
- struct rpki_uri **tmp;
struct rpki_uri *new;
int error;
if (uris->count + 1 >= uris->size) {
uris->size *= 2;
- tmp = realloc(uris->array,
+ uris->array = realloc(uris->array,
uris->size * sizeof(struct rpki_uri *));
- if (tmp == NULL)
- enomem_panic();
- uris->array = tmp;
}
uris->array[uris->count++] = new;
*/
original_size = get_spki_orig_size(lfile);
new_size = original_size + (original_size / BUF_SIZE);
- result = malloc(new_size + 1);
- if (result == NULL)
- enomem_panic();
-
- buf = malloc(BUF_SIZE);
- if (buf == NULL)
- enomem_panic();
+ result = pmalloc(new_size + 1);
+ buf = pmalloc(BUF_SIZE);
fd = lfile_fd(lfile);
offset = 0;
}
}
/* Reallocate to exact size and add nul char */
- if (offset != new_size) {
- eol = realloc(result, offset + 1);
- if (eol == NULL)
- enomem_panic();
- result = eol;
- }
+ if (offset != new_size)
+ result = prealloc(result, offset + 1);
free(buf);
result[offset] = '\0';
int error;
alloc_size = get_spki_alloc_size(lfile);
- tal->spki = malloc(alloc_size);
- if (tal->spki == NULL)
- enomem_panic();
+ tal->spki = pmalloc(alloc_size);
tmp = NULL;
error = base64_sanitize(lfile, &tmp);
return error;
}
- tal = malloc(sizeof(struct tal));
- if (tal == NULL)
- enomem_panic();
+ tal = pmalloc(sizeof(struct tal));
tal->file_name = file_name;
-
uris_init(&tal->uris);
-
error = read_uris(lfile, &tal->uris);
if (error)
goto fail;
-
error = read_spki(lfile, tal);
if (error)
goto fail;
/* Now order according to the priority */
http_first = (config_get_http_priority() > config_get_rsync_priority());
- ordered = malloc(tal->uris.size * sizeof(struct rpki_uri *));
- if (ordered == NULL)
- enomem_panic();
+ ordered = pmalloc(tal->uris.size * sizeof(struct rpki_uri *));
last_rsync = (http_first ? tal->uris.https_count : 0);
last_https = (http_first ? 0 : tal->uris.rsync_count);
if (error)
return error;
- thread = malloc(sizeof(struct validation_thread));
- if (thread == NULL)
- enomem_panic();
+ thread = pmalloc(sizeof(struct validation_thread));
- thread->tal_file = strdup(tal_file);
- if (thread->tal_file == NULL)
- enomem_panic();
+ thread->tal_file = pstrdup(tal_file);
thread->arg = t_param->db;
thread->exit_status = -EINTR;
thread->retry_local = true;
#include <errno.h>
#include <stdbool.h>
+#include "alloc.h"
#include "log.h"
/*
static void
double_line_size(struct vcard_line *line)
{
- uint8_t *tmp;
-
line->str.size *= 2;
- tmp = realloc(line->str.val, line->str.size);
- if (tmp == NULL)
- enomem_panic();
- line->str.val = tmp;
+ line->str.val = prealloc(line->str.val, line->str.size);
}
static void
line.str.size = 81; /* Okay default, assuming there is no folding. */
line.str.len = 0;
- line.str.val = malloc(line.str.size);
- if (line.str.val == NULL)
- enomem_panic();
+ line.str.val = pmalloc(line.str.size);
line.octet_string_offset = 0;
error = __handle_ghostbusters_vcard(vcard, &line);
#include <time.h>
#include "data_structure/uthash.h"
+#include "alloc.h"
#include "common.h"
#include "config.h"
#include "log.h"
struct error_uri *tmp;
int error;
- tmp = malloc(sizeof(struct error_uri));
- if (tmp == NULL)
- enomem_panic();
-
- /* Needed by uthash */
- memset(tmp, 0, sizeof(struct error_uri));
-
- tmp->uri = strdup(uri);
- if (tmp->uri == NULL)
- enomem_panic();
+ tmp = pzalloc(sizeof(struct error_uri)); /* Zero needed by uthash */
+ tmp->uri = pstrdup(uri);
error = get_current_time(&tmp->first_attempt);
if (error)
goto release_uri;
-
tmp->log_summary = false;
tmp->uri_related = NULL;
tmp->ref_by = NULL;
#include <errno.h>
#include <stdint.h> /* UINT32_MAX */
+#include "alloc.h"
#include "log.h"
#include "sorted_array.h"
#include "thread_var.h"
{
struct resources *result;
- result = malloc(sizeof(struct resources));
- if (result == NULL)
- return NULL;
+ result = pmalloc(sizeof(struct resources));
result->ip4s = NULL;
result->ip6s = NULL;
#include "rpp.h"
-#include <stdlib.h>
+#include "alloc.h"
#include "cert_stack.h"
#include "log.h"
#include "thread_var.h"
{
struct rpp *result;
- result = malloc(sizeof(struct rpp));
- if (result == NULL)
- return NULL;
+ result = pmalloc(sizeof(struct rpp));
uris_init(&result->certs);
result->crl.uri = NULL;
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
+#include "alloc.h"
#include "crypto/hash.h"
#include "common.h"
#include "log.h"
char *ptr;
int error;
- hash = malloc(HASH_LEN * sizeof(unsigned char));
- if (hash == NULL)
- enomem_panic();
+ hash = pmalloc(HASH_LEN * sizeof(unsigned char));
hash_len = 0;
error = hash_str("sha1", base, hash, &hash_len);
}
/* Get the first bytes + one slash + NUL char */
- tmp = malloc(OUT_LEN + 2);
- if (tmp == NULL)
- enomem_panic();
+ tmp = pmalloc(OUT_LEN + 2);
ptr = tmp;
for (i = 0; i < OUT_LEN / 2; i++) {
struct tal_elem *tmp;
int error;
- tmp = malloc(sizeof(struct tal_elem));
- if (tmp == NULL)
- enomem_panic();
+ tmp = pmalloc(sizeof(struct tal_elem));
tmp->uris = db_rrdp_uris_create();
tmp->visited = true;
- tmp->file_name = strdup(name);
- if (tmp->file_name == NULL)
- enomem_panic();
+ tmp->file_name = pstrdup(name);
error = get_workspace_path(name, &tmp->workspace);
if (error) {
#include <string.h>
#include <time.h>
#include "data_structure/uthash.h"
+#include "alloc.h"
#include "common.h"
#include "log.h"
#include "thread_var.h"
{
struct uris_table *tmp;
- tmp = malloc(sizeof(struct uris_table));
- if (tmp == NULL)
- enomem_panic();
- /* Needed by uthash */
- memset(tmp, 0, sizeof(struct uris_table));
-
- tmp->uri = strdup(uri);
- if (tmp->uri == NULL)
- enomem_panic();
-
- tmp->data.session_id = strdup(session_id);
- if (tmp->data.session_id == NULL)
- enomem_panic();
+ tmp = pzalloc(sizeof(struct uris_table)); /* Zero needed by uthash */
+ tmp->uri = pstrdup(uri);
+ tmp->data.session_id = pstrdup(session_id);
tmp->data.serial = serial;
tmp->last_update = 0;
tmp->request_status = req_status;
{
struct db_rrdp_uri *tmp;
- tmp = malloc(sizeof(struct db_rrdp_uri));
- if (tmp == NULL)
- enomem_panic();
-
+ tmp = pmalloc(sizeof(struct db_rrdp_uri));
tmp->table = NULL;
tmp->current_workspace = NULL;
#include <errno.h>
#include <stdlib.h>
#include <string.h>
+#include "alloc.h"
#include "log.h"
DEFINE_ARRAY_LIST_FUNCTIONS(deltas_head, struct delta_head, )
{
struct update_notification *result;
- result = malloc(sizeof(struct update_notification));
- if (result == NULL)
- return NULL;
+ result = pmalloc(sizeof(struct update_notification));
global_data_init(&result->global_data);
doc_data_init(&result->snapshot);
deltas_head_init(&result->deltas_list);
- result->uri = strdup(uri);
- if (result->uri == NULL) {
- free(result);
- return NULL;
- }
+ result->uri = pstrdup(uri);
return result;
}
{
struct snapshot *tmp;
- tmp = malloc(sizeof(struct snapshot));
- if (tmp == NULL)
- enomem_panic();
-
+ tmp = pmalloc(sizeof(struct snapshot));
global_data_init(&tmp->global_data);
return tmp;
{
struct delta *tmp;
- tmp = malloc(sizeof(struct delta));
- if (tmp == NULL)
- enomem_panic();
-
+ tmp = pmalloc(sizeof(struct delta));
global_data_init(&tmp->global_data);
return tmp;
{
struct publish *tmp;
- tmp = malloc(sizeof(struct publish));
- if (tmp == NULL)
- enomem_panic();
-
+ tmp = pmalloc(sizeof(struct publish));
doc_data_init(&tmp->doc_data);
tmp->content = NULL;
tmp->content_len = 0;
{
struct withdraw *tmp;
- tmp = malloc(sizeof(struct withdraw));
- if (tmp == NULL)
- enomem_panic();
-
+ tmp = pmalloc(sizeof(struct withdraw));
doc_data_init(&tmp->doc_data);
return tmp;
#include "crypto/hash.h"
#include "http/http.h"
#include "xml/relax_ng.h"
+#include "alloc.h"
#include "common.h"
#include "file.h"
#include "log.h"
return error;
if (original_size <= BUF_SIZE) {
- result = strdup(content);
- if (result == NULL)
- enomem_panic();
- *out = result;
+ *out = pstrdup(content);
return 0;
}
new_size = original_size + (original_size / BUF_SIZE);
- result = malloc(new_size + 1);
- if (result == NULL)
- enomem_panic();
+ result = pmalloc(new_size + 1);
offset = 0;
while (original_size > 0){
}
/* Reallocate to exact size and add nul char */
- if (offset != new_size + 1) {
- tmp = realloc(result, offset + 1);
- if (tmp == NULL)
- enomem_panic();
- result = tmp;
- }
+ if (offset != new_size + 1)
+ result = prealloc(result, offset + 1);
result[offset] = '\0';
*out = result;
}
alloc_size = EVP_DECODE_LENGTH(strlen(content));
- result = malloc(alloc_size);
- if (result == NULL)
- enomem_panic();
+ result = pmalloc(alloc_size);
error = base64_decode(encoded, result, true, alloc_size, &result_len);
if (error)
attr, xmlTextReaderConstLocalName(reader));
}
- tmp = malloc(xmlStrlen(xml_value) + 1);
- if (tmp == NULL)
- enomem_panic();
-
+ tmp = pmalloc(xmlStrlen(xml_value) + 1);
memcpy(tmp, xml_value, xmlStrlen(xml_value));
tmp[xmlStrlen(xml_value)] = '\0';
xmlFree(xml_value);
}
tmp_len = xmlStrlen(xml_value) / 2;
- tmp = malloc(tmp_len);
- if (tmp == NULL)
- enomem_panic();
- memset(tmp, 0, tmp_len);
+ tmp = pzalloc(tmp_len);
ptr = tmp;
xml_cur = (char *) xml_value;
if (error)
goto release_base64;
- error = hash_validate_file("sha256", uri, tmp->doc_data.hash,
+ error = hash_validate_file(uri, tmp->doc_data.hash,
tmp->doc_data.hash_len);
uri_refput(uri);
if (error != 0) {
if (error)
goto release_tmp;
- error = hash_validate_file("sha256", uri,
- tmp->doc_data.hash, tmp->doc_data.hash_len);
+ error = hash_validate_file(uri, tmp->doc_data.hash,
+ tmp->doc_data.hash_len);
if (error)
goto release_uri;
fnstack_push_uri(uri);
/* Hash validation */
- error = hash_validate_file("sha256", uri, args->parent->snapshot.hash,
+ error = hash_validate_file(uri, args->parent->snapshot.hash,
args->parent->snapshot.hash_len);
if (error)
goto pop;
expected_data = &parents_data->doc_data;
fnstack_push_uri(uri);
- error = hash_validate_file("sha256", uri, expected_data->hash,
+ error = hash_validate_file(uri, expected_data->hash,
expected_data->hash_len);
if (error)
goto pop_fnstack;
#include <sys/stat.h>
#include <sys/wait.h>
+#include "alloc.h"
#include "common.h"
#include "config.h"
#include "log.h"
{
struct uri_list *visited_uris;
- visited_uris = malloc(sizeof(struct uri_list));
- if (visited_uris == NULL)
- enomem_panic();
-
+ visited_uris = pmalloc(sizeof(struct uri_list));
SLIST_INIT(visited_uris);
+
return visited_uris;
}
{
struct uri *node;
- node = malloc(sizeof(struct uri));
- if (node == NULL)
- enomem_panic();
-
+ node = pmalloc(sizeof(struct uri));
node->uri = uri;
uri_refget(uri);
* and we need to add the program name (for some reason) and NULL
* elements, and replace $REMOTE and $LOCAL.
*/
- copy_args = calloc(config_args->length + 2, sizeof(char *));
- if (copy_args == NULL)
- enomem_panic();
+ copy_args = pcalloc(config_args->length + 2, sizeof(char *));
copy_args[0] = config_get_rsync_program();
copy_args[config_args->length + 1] = NULL;
for (i = 0; i < config_args->length; i++) {
if (strcmp(config_args->array[i], "$REMOTE") == 0)
- copy_args[i + 1] = strdup(uri_get_global(uri));
+ copy_args[i + 1] = pstrdup(uri_get_global(uri));
else if (strcmp(config_args->array[i], "$LOCAL") == 0)
- copy_args[i + 1] = strdup(uri_get_local(uri));
+ copy_args[i + 1] = pstrdup(uri_get_local(uri));
else
- copy_args[i + 1] = strdup(config_args->array[i]);
-
- if (copy_args[i + 1] == NULL)
- enomem_panic();
+ copy_args[i + 1] = pstrdup(config_args->array[i]);
}
*args = copy_args;
#define PRE_RSYNC "[RSYNC exec]: "
char *cpy, *cur, *tmp;
- cpy = malloc(read + 1);
- if (cpy == NULL)
- enomem_panic();
+ cpy = pmalloc(read + 1);
strncpy(cpy, buffer, read);
cpy[read] = '\0';
#include <sys/types.h> /* AF_INET, AF_INET6 (needed in OpenBSD) */
#include <sys/socket.h> /* AF_INET, AF_INET6 (needed in OpenBSD) */
+#include "alloc.h"
#include "log.h"
#include "data_structure/uthash.h"
{
struct db_table *table;
- table = malloc(sizeof(struct db_table));
- if (table == NULL)
- return NULL;
-
+ table = pmalloc(sizeof(struct db_table));
table->roas = NULL;
table->router_keys = NULL;
+
return table;
}
struct hashable_roa *old;
int error;
- new = malloc(sizeof(struct hashable_roa));
- if (new == NULL)
- enomem_panic();
- memcpy(new, stack_new, sizeof(*new));
+ new = pmclone(stack_new, sizeof(struct hashable_roa));
errno = 0;
HASH_REPLACE(hh, table->roas, data, sizeof(new->data), new, old);
struct hashable_key *key;
int error;
- key = malloc(sizeof(struct hashable_key));
- if (key == NULL)
- enomem_panic();
- /* Needed by uthash */
- memset(key, 0, sizeof(struct hashable_key));
+ key = pzalloc(sizeof(struct hashable_key)); /* Zero needed by uthash */
router_key_init(&key->data, ski, as, spk);
#include <stdatomic.h>
#include <sys/types.h> /* AF_INET, AF_INET6 (needed in OpenBSD) */
#include <sys/socket.h> /* AF_INET, AF_INET6 (needed in OpenBSD) */
+#include "alloc.h"
#include "types/address.h"
#include "data_structure/array_list.h"
{
struct deltas *result;
- result = malloc(sizeof(struct deltas));
- if (result == NULL)
- enomem_panic();
+ result = pmalloc(sizeof(struct deltas));
deltas_v4_init(&result->v4.adds);
deltas_v4_init(&result->v4.removes);
#include <limits.h>
#include <errno.h>
+#include "alloc.h"
#include "config.h"
#include "log.h"
{
struct deltas_array *result;
- result = malloc(sizeof(struct deltas_array));
- if (result == NULL)
- enomem_panic();
+ result = pmalloc(sizeof(struct deltas_array));
- result->array = calloc(config_get_deltas_lifetime(),
+ result->array = pcalloc(config_get_deltas_lifetime(),
sizeof(struct deltas *));
- if (result->array == NULL)
- enomem_panic();
-
result->len = 0;
result->last = UINT_MAX;
+
return result;
}
#include <time.h>
#include <sys/queue.h>
+#include "alloc.h"
#include "common.h"
#include "output_printer.h"
#include "validation_handler.h"
return 0;
}
- ptr = malloc(sizeof(struct vrp_node));
- if (ptr == NULL)
- enomem_panic();
-
+ ptr = pmalloc(sizeof(struct vrp_node));
ptr->delta = *delta;
SLIST_INSERT_HEAD(filtered_vrps, ptr, next);
+
return 0;
}
}
}
- ptr = malloc(sizeof(struct rk_node));
- if (ptr == NULL)
- enomem_panic();
-
+ ptr = pmalloc(sizeof(struct rk_node));
ptr->delta = *delta;
SLIST_INSERT_HEAD(filtered_keys, ptr, next);
+
return 0;
}
#include "err_pdu.h"
#include <unistd.h>
+#include "alloc.h"
#include "pdu_sender.h"
#include "log.h"
*/
/* Need a clone to remove the const. */
- message = (message_const != NULL) ? strdup(message_const) : NULL;
+ message = (message_const != NULL) ? pstrdup(message_const) : NULL;
send_error_report_pdu(fd, version, code, request, message);
free(message);
#include <string.h>
#include <syslog.h>
+#include "alloc.h"
#include "common.h"
#include "log.h"
#include "types/address.h"
return RESPOND_ERROR(err_pdu_send_unsupported_pdu_type(
client->fd, client->rtr_version, request));
- request->pdu = malloc(meta->length);
- if (request->pdu == NULL)
- /* No error report PDU on allocation failures. */
- enomem_panic();
+ request->pdu = pmalloc(meta->length);
error = meta->from_stream(&header, reader, request->pdu);
if (error) {
#include <unistd.h>
#include <arpa/inet.h> /* INET_ADDRSTRLEN */
+#include "alloc.h"
#include "common.h"
#include "config.h"
#include "log.h"
+ 4 /* Length of Error Text field */
+ pdu.error_message_length;
- data = malloc(pdu.header.length);
- if (data == NULL)
- enomem_panic();
+ data = pmalloc(pdu.header.length);
len = serialize_error_report_pdu(&pdu, data);
if (len != pdu.header.length)
#include <unistd.h>
#include <netinet/in.h>
+#include "alloc.h"
#include "log.h"
static int get_octets(unsigned char);
* to be relatively small now.
*/
- string = malloc(string_len + 1); /* Include NULL chara. */
- if (string == NULL)
- enomem_panic();
+ string = pmalloc(string_len + 1); /* Include NULL chara. */
memcpy(string, reader->buffer, string_len);
reader->buffer += string_len;
#include <sys/types.h>
#include <sys/socket.h>
+#include "alloc.h"
#include "config.h"
#include "types/address.h"
#include "data_structure/array_list.h"
if (full_address == NULL) {
tmp_addr = NULL;
- tmp_serv = strdup(config_get_server_port());
- if (tmp_serv == NULL)
- enomem_panic();
+ tmp_serv = pstrdup(config_get_server_port());
goto done;
}
ptr = strrchr(full_address, '#');
if (ptr == NULL) {
- tmp_addr = strdup(full_address);
- if (tmp_addr == NULL)
- enomem_panic();
-
- tmp_serv = strdup(config_get_server_port());
- if (tmp_serv == NULL)
- enomem_panic();
-
+ tmp_addr = pstrdup(full_address);
+ tmp_serv = pstrdup(config_get_server_port());
goto done;
}
full_address);
tmp_addr_len = strlen(full_address) - strlen(ptr);
- tmp_addr = malloc(tmp_addr_len + 1);
- if (tmp_addr == NULL)
- enomem_panic();
+ tmp_addr = pmalloc(tmp_addr_len + 1);
memcpy(tmp_addr, full_address, tmp_addr_len);
tmp_addr[tmp_addr_len] = '\0';
- tmp_serv = strdup(ptr + 1);
- if (tmp_serv == NULL)
- enomem_panic();
-
+ tmp_serv = pstrdup(ptr + 1);
/* Fall through */
done:
*address = tmp_addr;
server.fd = fd;
/* Ignore failure; this is just a nice-to-have. */
- server.addr = (input_addr != NULL) ? strdup(input_addr) : NULL;
+ server.addr = (input_addr != NULL) ? pstrdup(input_addr) : NULL;
server_arraylist_add(&servers, &server);
return 0; /* Happy path */
{
struct client_request *request;
- request = malloc(sizeof(struct client_request));
- if (request == NULL)
- enomem_panic();
+ request = pmalloc(sizeof(struct client_request));
request->client = client;
if (!read_until_block(client->fd, request)) {
unsigned int i;
int error;
- pollfds = calloc(servers.len + clients.len, sizeof(struct pollfd));
- if (pollfds == NULL) {
- enomem_panic();
- return PV_RETRY;
- }
+ pollfds = pcalloc(servers.len + clients.len, sizeof(struct pollfd));
ARRAYLIST_FOREACH(&servers, server, i)
init_pollfd(&pollfds[i], server->fd);
#include <time.h>
#include <arpa/inet.h>
+#include "alloc.h"
#include "common.h"
#include "crypto/base64.h"
#include "data_structure/array_list.h"
{
struct slurm_lists *cache;
- cache = malloc(sizeof(struct slurm_lists));
- if (cache == NULL)
- enomem_panic();
+ cache = pmalloc(sizeof(struct slurm_lists));
al_filter_prefix_init(&cache->filter_pfx_al);
al_assertion_prefix_init(&cache->assertion_pfx_al);
struct db_slurm *db;
int error;
- db = malloc(sizeof(struct db_slurm));
- if (db == NULL)
- enomem_panic();
+ db = pmalloc(sizeof(struct db_slurm));
error = get_current_time(&db->loaded_date);
if (error) {
#include <sys/types.h> /* AF_INET, AF_INET6 (needed in OpenBSD) */
#include <sys/socket.h> /* AF_INET, AF_INET6 (needed in OpenBSD) */
+#include "alloc.h"
#include "log.h"
#include "config.h"
#include "common.h"
{
struct slurm_csum_list *list;
struct slurm_file_csum *csum;
- int error;
- csum = malloc(sizeof(struct slurm_file_csum));
- if (csum == NULL)
- enomem_panic();
+ csum = pmalloc(sizeof(struct slurm_file_csum));
- error = hash_local_file("sha256", location, csum->csum,
- &csum->csum_len);
- if (error) {
+ if (hash_local_file(location, csum->csum, &csum->csum_len) != 0) {
free(csum);
return pr_op_err("Calculating slurm hash");
}
#include "crypto/base64.h"
#include "algorithm.h"
+#include "alloc.h"
#include "log.h"
#include "json_parser.h"
#include "types/address.h"
} else if (error)
return error;
- clone = strdup(str_prefix);
- if (clone == NULL)
- enomem_panic();
+ clone = pstrdup(str_prefix);
token = strtok(clone, "/");
isv4 = strchr(token, ':') == NULL;
#include <errno.h>
#include <stdlib.h>
#include <string.h>
+
+#include "alloc.h"
#include "log.h"
struct sorted_array {
{
struct sorted_array *result;
- result = malloc(sizeof(struct sorted_array));
- if (result == NULL)
- return NULL;
+ result = pmalloc(sizeof(struct sorted_array));
- result->array = calloc(8, elem_size);
- if (result->array == NULL) {
- free(result);
- return NULL;
- }
+ result->array = pcalloc(8, elem_size);
result->count = 0;
result->len = 8;
result->size = elem_size;
sarray_add(struct sorted_array *sarray, void *element)
{
int error;
- void *tmp;
error = compare(sarray, element);
if (error)
return error;
if (sarray->count >= sarray->len) {
- tmp = realloc(sarray->array, 2 * sarray->len * sarray->size);
- if (tmp == NULL)
- enomem_panic();
- sarray->array = tmp;
+ sarray->array = realloc(sarray->array,
+ 2 * sarray->len * sarray->size);
sarray->len *= 2;
}
#include <errno.h>
#include "rrdp/db/db_rrdp.h"
+#include "alloc.h"
#include "log.h"
#include "thread_var.h"
X509_VERIFY_PARAM *params;
int error;
- result = malloc(sizeof(struct validation));
- if (!result)
- enomem_panic();
+ result = pmalloc(sizeof(struct validation));
error = state_store(result);
if (error)
#include <errno.h>
#include <string.h>
+
+#include "alloc.h"
#include "log.h"
/**
{
char *result;
- result = malloc(size + 1);
- if (result == NULL)
- enomem_panic();
+ result = pmalloc(size + 1);
memcpy(result, string, size);
result[size] = '\0';
}
written = BIO_number_written(bio);
- result = malloc(written + 1);
- if (result == NULL)
- enomem_panic();
+ result = pmalloc(written + 1);
BIO_read(bio, result, written);
result[written] = '\0';
#include <pthread.h>
#include <stdlib.h>
#include <string.h>
+#include "alloc.h"
#include "common.h"
#include "log.h"
{
struct thread_pool_task *task;
- task = malloc(sizeof(struct thread_pool_task));
- if (task == NULL)
- enomem_panic();
+ task = pmalloc(sizeof(struct thread_pool_task));
task->name = name;
task->cb = cb;
struct thread_pool *result;
int error;
- result = malloc(sizeof(struct thread_pool));
- if (result == NULL)
- enomem_panic();
+ result = pmalloc(sizeof(struct thread_pool));
/* Init locking */
error = pthread_mutex_init(&result->lock, NULL);
result->stop = false;
result->working_count = 0;
result->thread_count = 0;
- result->thread_ids = calloc(threads, sizeof(pthread_t));
- if (result->thread_ids == NULL)
- enomem_panic();
+ result->thread_ids = pcalloc(threads, sizeof(pthread_t));
result->thread_ids_len = threads;
error = spawn_threads(result);
#include <arpa/inet.h>
#include <sys/socket.h>
+#include "alloc.h"
#include "config.h"
static pthread_key_t state_key;
struct filename_stack *files;
int error;
- files = malloc(sizeof(struct filename_stack));
- if (files == NULL)
- enomem_panic();
-
- files->filenames = malloc(32 * sizeof(char *));
- if (files->filenames == NULL)
- enomem_panic();
+ files = pmalloc(sizeof(struct filename_stack));
+ files->filenames = pmalloc(32 * sizeof(char *));
files->len = 0;
files->size = 32;
fnstack_push(char const *file)
{
struct filename_stack *files;
- char const **tmp;
files = pthread_getspecific(filenames_key);
if (files == NULL || files->filenames == NULL)
return;
if (files->len >= files->size) {
- tmp = realloc(files->filenames, 2 * files->size * sizeof(char *));
- if (tmp == NULL)
- enomem_panic();
- files->filenames = tmp;
+ files->filenames = prealloc(files->filenames,
+ 2 * files->size * sizeof(char *));
files->size *= 2;
}
struct working_repo *repo;
int error;
- repo = malloc(sizeof(struct working_repo));
- if (repo == NULL)
- enomem_panic();
+ repo = pmalloc(sizeof(struct working_repo));
repo->uri = NULL;
repo->level = 0;
#include <errno.h>
#include <strings.h>
#include "rrdp/db/db_rrdp_uris.h"
+#include "alloc.h"
#include "common.h"
#include "config.h"
#include "log.h"
return error;
}
- uri->global = malloc(str_len + 1);
- if (uri->global == NULL)
- enomem_panic();
+ uri->global = pmalloc(str_len + 1);
strncpy(uri->global, str, str_len);
uri->global[str_len] = '\0';
uri->global_len = str_len;
return pr_val_err("Manifest URL '%s' contains no slashes.", mft);
dir_len = (slash_pos + 1) - mft;
- joined = malloc(dir_len + ia5->size + 1);
- if (joined == NULL)
- enomem_panic();
+ joined = pmalloc(dir_len + ia5->size + 1);
strncpy(joined, mft, dir_len);
strncpy(joined + dir_len, (char *) ia5->buf, ia5->size);
get_local_workspace(void)
{
char const *workspace;
- char *tmp;
workspace = db_rrdp_uris_workspace_get();
if (workspace == NULL)
return NULL;
- tmp = strdup(workspace);
- if (tmp == NULL)
- enomem_panic();
-
- return tmp;
+ return pstrdup(workspace);
}
/**
struct rpki_uri *uri;
int error;
- uri = malloc(sizeof(struct rpki_uri));
- if (uri == NULL)
- enomem_panic();
+ uri = pmalloc(sizeof(struct rpki_uri));
error = str2global(guri, guri_len, uri);
if (error) {
uint8_t flags;
int error;
- uri = malloc(sizeof(struct rpki_uri));
- if (uri == NULL)
- enomem_panic();
+ uri = pmalloc(sizeof(struct rpki_uri));
error = ia5str2global(uri, mft->global, ia5);
if (error) {
#include <sys/queue.h>
#include <stddef.h>
#include <string.h>
+#include "alloc.h"
#include "log.h"
#include "delete_dir_daemon.h"
#include "data_structure/array_list.h"
{
struct visited_elem *tmp;
- tmp = malloc(sizeof(struct visited_elem));
- if (tmp == NULL)
- enomem_panic();
- /* Needed by uthash */
- memset(tmp, 0, sizeof(struct visited_elem));
-
- tmp->uri = strdup(uri);
- if (tmp->uri == NULL) {
- free(tmp);
- enomem_panic();
- }
+ tmp = pzalloc(sizeof(struct visited_elem)); /* Zero needed by uthash */
+ tmp->uri = pstrdup(uri);
return tmp;
}
{
struct visited_uris *tmp;
- tmp = malloc(sizeof(struct visited_uris));
- if (tmp == NULL)
- enomem_panic();
+ tmp = pmalloc(sizeof(struct visited_uris));
tmp->table = NULL;
tmp->refs = 1;
for (elem = uris->table; elem != NULL; elem = elem->hh.next) {
last_slash = strrchr(elem->uri, '/');
size = last_slash - elem->uri;
- tmp = malloc(size + 1);
- if (tmp == NULL)
- enomem_panic();
+ tmp = pmalloc(size + 1);
strncpy(tmp, elem->uri, size);
tmp[size] = '\0';
uris_roots_add(roots, &tmp);
#include <errno.h>
#include <stdlib.h>
+#include "alloc.c"
#include "file.c"
#include "impersonator.c"
#include "line_file.c"
#include <errno.h>
#include <stdlib.h>
+#include "alloc.c"
#include "impersonator.c"
#include "log.c"
#include "rrdp/rrdp_objects.c"
#include <errno.h>
#include <stdlib.h>
+#include "alloc.c"
#include "common.c"
#include "log.c"
#include "impersonator.c"
#include <check.h>
#include <stdlib.h>
+#include "alloc.c"
#include "common.c"
#include "log.c"
#include "impersonator.c"
#include <check.h>
#include <stdlib.h>
+#include "alloc.c"
#include "log.c"
#include "impersonator.c"
#include "types/address.c"
#include "crypto/base64.c"
#include "algorithm.c"
+#include "alloc.c"
#include "common.c"
#include "file.c"
#include "impersonator.c"
#include <sys/queue.h>
#include "algorithm.c"
+#include "alloc.c"
#include "common.c"
#include "file.c"
#include "impersonator.c"
#include <stdio.h>
#include <unistd.h>
+#include "alloc.c"
#include "common.c"
#include "log.c"
#include "impersonator.c"
#include <stdlib.h>
#include <string.h>
+#include "alloc.c"
#include "impersonator.c"
#include "log.c"
#include "rtr/primitive_reader.c"
#include <stdlib.h>
#include "common.h"
+#include "alloc.c"
#include "file.c"
#include "impersonator.c"
#include "line_file.c"
#include <stdlib.h>
#include <unistd.h>
+#include "alloc.c"
#include "common.c"
#include "log.c"
#include "impersonator.c"
#include <errno.h>
#include <stdlib.h>
+#include "alloc.c"
#include "common.c"
#include "log.c"
#include "impersonator.c"
#include <errno.h>
#include <stdint.h>
+#include "alloc.c"
#include "common.c"
#include "log.c"
#include "impersonator.c"
#include <check.h>
+#include "alloc.c"
#include "log.c"
#include "impersonator.c"
#include "object/vcard.c"