Use "unable to allocate memory" warning on malloc failure.

This is consistent with the rest of the sudo source code.
This commit is contained in:
Todd C. Miller
2022-06-29 10:00:03 -06:00
parent 3e21c8da5c
commit 54ed54d94e
2 changed files with 26 additions and 24 deletions

View File

@@ -354,7 +354,7 @@ cb_iolog_dir(struct logsrvd_config *config, const char *path, size_t offset)
free(config->iolog.iolog_dir);
if ((config->iolog.iolog_dir = strdup(path)) == NULL) {
sudo_warn(NULL);
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
debug_return_bool(false);
}
debug_return_bool(true);
@@ -367,7 +367,7 @@ cb_iolog_file(struct logsrvd_config *config, const char *path, size_t offset)
free(config->iolog.iolog_file);
if ((config->iolog.iolog_file = strdup(path)) == NULL) {
sudo_warn(NULL);
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
debug_return_bool(false);
}
debug_return_bool(true);
@@ -508,7 +508,7 @@ append_address(struct server_address_list *addresses, const char *str,
debug_decl(append_address, SUDO_DEBUG_UTIL);
if ((copy = strdup(str)) == NULL) {
sudo_warn(NULL);
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
debug_return_bool(false);
}
@@ -531,11 +531,11 @@ append_address(struct server_address_list *addresses, const char *str,
/* Only make a single copy of the string + host for all addresses. */
if ((sa_str = sudo_rcstr_dup(str)) == NULL) {
sudo_warn(NULL);
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
goto done;
}
if (host != NULL && (sa_host = sudo_rcstr_dup(host)) == NULL) {
sudo_warn(NULL);
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
goto done;
}
@@ -553,7 +553,7 @@ append_address(struct server_address_list *addresses, const char *str,
struct server_address *addr;
if ((addr = malloc(sizeof(*addr))) == NULL) {
sudo_warn(NULL);
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
goto done;
}
addr->sa_str = sudo_rcstr_addref(sa_str);
@@ -623,7 +623,7 @@ cb_server_pid_file(struct logsrvd_config *config, const char *str, size_t offset
debug_return_bool(false);
}
if ((copy = strdup(str)) == NULL) {
sudo_warn(NULL);
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
debug_return_bool(false);
}
}
@@ -646,7 +646,8 @@ cb_server_log(struct logsrvd_config *config, const char *str, size_t offset)
if (*str == '/') {
log_type = SERVER_LOG_FILE;
if ((copy = strdup(str)) == NULL) {
sudo_warn(NULL);
sudo_warnx(U_("%s: %s"), __func__,
U_("unable to allocate memory"));
debug_return_bool(false);
}
} else if (strcmp(str, "stderr") == 0) {
@@ -674,7 +675,7 @@ cb_tls_key(struct logsrvd_config *config, const char *path, size_t offset)
free(*p);
if ((*p = strdup(path)) == NULL) {
sudo_warn(NULL);
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
debug_return_bool(false);
}
debug_return_bool(true);
@@ -688,7 +689,7 @@ cb_tls_cacert(struct logsrvd_config *config, const char *path, size_t offset)
free(*p);
if ((*p = strdup(path)) == NULL) {
sudo_warn(NULL);
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
debug_return_bool(false);
}
debug_return_bool(true);
@@ -702,7 +703,7 @@ cb_tls_cert(struct logsrvd_config *config, const char *path, size_t offset)
free(*p);
if ((*p = strdup(path)) == NULL) {
sudo_warn(NULL);
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
debug_return_bool(false);
}
debug_return_bool(true);
@@ -716,7 +717,7 @@ cb_tls_dhparams(struct logsrvd_config *config, const char *path, size_t offset)
free(*p);
if ((*p = strdup(path)) == NULL) {
sudo_warn(NULL);
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
debug_return_bool(false);
}
debug_return_bool(true);
@@ -730,7 +731,7 @@ cb_tls_ciphers12(struct logsrvd_config *config, const char *str, size_t offset)
free(*p);
if ((*p = strdup(str)) == NULL) {
sudo_warn(NULL);
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
debug_return_bool(false);
}
debug_return_bool(true);
@@ -744,7 +745,7 @@ cb_tls_ciphers13(struct logsrvd_config *config, const char *str, size_t offset)
free(*p);
if ((*p = strdup(str)) == NULL) {
sudo_warn(NULL);
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
debug_return_bool(false);
}
debug_return_bool(true);
@@ -825,7 +826,7 @@ cb_relay_dir(struct logsrvd_config *config, const char *str, size_t offset)
debug_decl(cb_relay_dir, SUDO_DEBUG_UTIL);
if ((copy = strdup(str)) == NULL) {
sudo_warn(NULL);
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
debug_return_bool(false);
}
@@ -1033,7 +1034,7 @@ cb_logfile_path(struct logsrvd_config *config, const char *str, size_t offset)
debug_return_bool(false);
}
if ((copy = strdup(str)) == NULL) {
sudo_warn(NULL);
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
debug_return_bool(false);
}
@@ -1050,7 +1051,7 @@ cb_logfile_time_format(struct logsrvd_config *config, const char *str, size_t of
debug_decl(cb_logfile_time_format, SUDO_DEBUG_UTIL);
if ((copy = strdup(str)) == NULL) {
sudo_warn(NULL);
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
debug_return_bool(false);
}
@@ -1592,7 +1593,7 @@ logsrvd_conf_alloc(void)
debug_decl(logsrvd_conf_alloc, SUDO_DEBUG_UTIL);
if ((config = calloc(1, sizeof(*config))) == NULL) {
sudo_warn(NULL);
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
debug_return_ptr(NULL);
}
@@ -1618,7 +1619,7 @@ logsrvd_conf_alloc(void)
config->server.log_type = SERVER_LOG_SYSLOG;
config->server.pid_file = strdup(_PATH_SUDO_LOGSRVD_PID);
if (config->server.pid_file == NULL) {
sudo_warn(NULL);
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
goto bad;
}
@@ -1630,20 +1631,20 @@ logsrvd_conf_alloc(void)
if (access(DEFAULT_CA_CERT_PATH, R_OK) == 0) {
config->server.tls_cacert_path = strdup(DEFAULT_CA_CERT_PATH);
if (config->server.tls_cacert_path == NULL) {
sudo_warn(NULL);
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
goto bad;
}
}
if (access(DEFAULT_SERVER_CERT_PATH, R_OK) == 0) {
config->server.tls_cert_path = strdup(DEFAULT_SERVER_CERT_PATH);
if (config->server.tls_cert_path == NULL) {
sudo_warn(NULL);
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
goto bad;
}
}
config->server.tls_key_path = strdup(DEFAULT_SERVER_KEY_PATH);
if (config->server.tls_key_path == NULL) {
sudo_warn(NULL);
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
goto bad;
}
config->server.tls_verify = true;
@@ -1739,7 +1740,8 @@ logsrvd_conf_apply(struct logsrvd_config *config)
config->server.tls_cert_path =
strdup(DEFAULT_SERVER_CERT_PATH);
if (config->server.tls_cert_path == NULL) {
sudo_warn(NULL);
sudo_warnx(U_("%s: %s"), __func__,
U_("unable to allocate memory"));
debug_return_bool(false);
}
}

View File

@@ -288,7 +288,7 @@ read_io_buf(struct client_closure *closure)
free(closure->buf);
closure->bufsize = sudo_pow2_roundup(timing->u.nbytes);
if ((closure->buf = malloc(closure->bufsize)) == NULL) {
sudo_warn(NULL);
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
timing->u.nbytes = 0;
debug_return_bool(false);
}