diff --git a/source3/intl/lang_tdb.c b/source3/intl/lang_tdb.c index bb780c5feda..6ad9ef8496b 100644 --- a/source3/intl/lang_tdb.c +++ b/source3/intl/lang_tdb.c @@ -127,7 +127,11 @@ bool lang_tdb_init(const char *lang) if (!lang) return True; - asprintf(&msg_path, "%s.msg", data_path((const char *)lang)); + if (asprintf(&msg_path, "%s.msg", + data_path((const char *)lang)) == -1) { + DEBUG(0, ("asprintf failed\n")); + goto done; + } if (stat(msg_path, &st) != 0) { /* the msg file isn't available */ DEBUG(10, ("lang_tdb_init: %s: %s\n", msg_path, @@ -135,7 +139,10 @@ bool lang_tdb_init(const char *lang) goto done; } - asprintf(&path, "%s%s.tdb", lock_path("lang_"), lang); + if (asprintf(&path, "%s%s.tdb", lock_path("lang_"), lang) == -1) { + DEBUG(0, ("asprintf failed\n")); + goto done; + } DEBUG(10, ("lang_tdb_init: loading %s\n", path)); diff --git a/source3/lib/debug.c b/source3/lib/debug.c index 9ff267b6079..c4a0d1b47be 100644 --- a/source3/lib/debug.c +++ b/source3/lib/debug.c @@ -827,6 +827,7 @@ void check_log_size( void ) }; int priority; char *msgbuf = NULL; + int ret; if( syslog_level >= ( sizeof(priority_map) / sizeof(priority_map[0]) ) || syslog_level < 0) priority = LOG_DEBUG; @@ -834,10 +835,10 @@ void check_log_size( void ) priority = priority_map[syslog_level]; va_start(ap, format_str); - vasprintf(&msgbuf, format_str, ap); + ret = vasprintf(&msgbuf, format_str, ap); va_end(ap); - if (msgbuf) { + if (ret == -1) { syslog(priority, "%s", msgbuf); } SAFE_FREE(msgbuf); @@ -1059,12 +1060,13 @@ bool dbghdr(int level, int cls, const char *file, const char *func, int line) va_list ap; char *msgbuf = NULL; bool ret = true; + int res; va_start(ap, format_str); - vasprintf(&msgbuf, format_str, ap); + res = vasprintf(&msgbuf, format_str, ap); va_end(ap); - if (msgbuf) { + if (res != -1) { format_debug_text(msgbuf); } else { ret = false; diff --git a/source3/lib/gencache.c b/source3/lib/gencache.c index 663385cfe3d..6131269adbd 100644 --- a/source3/lib/gencache.c +++ b/source3/lib/gencache.c @@ -120,9 +120,9 @@ bool gencache_set(const char *keystr, const char *value, time_t timeout) if (!gencache_init()) return False; - asprintf(&valstr, CACHE_DATA_FMT, (int)timeout, value); - if (!valstr) + if (asprintf(&valstr, CACHE_DATA_FMT, (int)timeout, value) == -1) { return False; + } databuf = string_term_tdb_data(valstr); DEBUG(10, ("Adding cache entry with key = %s; value = %s and timeout =" @@ -340,8 +340,7 @@ bool gencache_set_data_blob(const char *keystr, DATA_BLOB *blob, time_t timeout) return False; } - asprintf(&valstr, "%12u/%s", (int)timeout, BLOB_TYPE); - if (!valstr) { + if (asprintf(&valstr, "%12u/%s", (int)timeout, BLOB_TYPE) == -1) { return False; } @@ -452,8 +451,9 @@ void gencache_iterate(void (*fn)(const char* key, const char *value, time_t time break; } - asprintf(&fmt, READ_CACHE_DATA_FMT_TEMPLATE, (unsigned int)databuf.dsize - TIMEOUT_LEN); - if (!fmt) { + if (asprintf(&fmt, READ_CACHE_DATA_FMT_TEMPLATE, + (unsigned int)databuf.dsize - TIMEOUT_LEN) + == -1) { SAFE_FREE(valstr); SAFE_FREE(entry); SAFE_FREE(keystr); diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c index e040f4631a0..a7c35c48878 100644 --- a/source3/lib/util_sock.c +++ b/source3/lib/util_sock.c @@ -1904,8 +1904,7 @@ int create_pipe_sock(const char *socket_dir, goto out_close; } - asprintf(&path, "%s/%s", socket_dir, socket_name); - if (!path) { + if (asprintf(&path, "%s/%s", socket_dir, socket_name) == -1) { goto out_close; } diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c index f631dfffeed..cb8a100fa7b 100644 --- a/source3/lib/util_str.c +++ b/source3/lib/util_str.c @@ -2086,6 +2086,7 @@ static char *ipstr_list_add(char **ipstr_list, const struct ip_service *service) { char *new_ipstr = NULL; char addr_buf[INET6_ADDRSTRLEN]; + int ret; /* arguments checking */ if (!ipstr_list || !service) { @@ -2100,33 +2101,30 @@ static char *ipstr_list_add(char **ipstr_list, const struct ip_service *service) if (*ipstr_list) { if (service->ss.ss_family == AF_INET) { /* IPv4 */ - asprintf(&new_ipstr, "%s%s%s:%d", - *ipstr_list, - IPSTR_LIST_SEP, - addr_buf, - service->port); + ret = asprintf(&new_ipstr, "%s%s%s:%d", *ipstr_list, + IPSTR_LIST_SEP, addr_buf, + service->port); } else { /* IPv6 */ - asprintf(&new_ipstr, "%s%s[%s]:%d", - *ipstr_list, - IPSTR_LIST_SEP, - addr_buf, - service->port); + ret = asprintf(&new_ipstr, "%s%s[%s]:%d", *ipstr_list, + IPSTR_LIST_SEP, addr_buf, + service->port); } SAFE_FREE(*ipstr_list); } else { if (service->ss.ss_family == AF_INET) { /* IPv4 */ - asprintf(&new_ipstr, "%s:%d", - addr_buf, - service->port); + ret = asprintf(&new_ipstr, "%s:%d", addr_buf, + service->port); } else { /* IPv6 */ - asprintf(&new_ipstr, "[%s]:%d", - addr_buf, - service->port); + ret = asprintf(&new_ipstr, "[%s]:%d", addr_buf, + service->port); } } + if (ret == -1) { + return NULL; + } *ipstr_list = new_ipstr; return *ipstr_list; } diff --git a/source3/lib/util_tdb.c b/source3/lib/util_tdb.c index dd5ebcd7ab5..724832ea5bb 100644 --- a/source3/lib/util_tdb.c +++ b/source3/lib/util_tdb.c @@ -669,12 +669,13 @@ static void tdb_log(TDB_CONTEXT *tdb, enum tdb_debug_level level, const char *fo { va_list ap; char *ptr = NULL; + int ret; va_start(ap, format); - vasprintf(&ptr, format, ap); + ret = vasprintf(&ptr, format, ap); va_end(ap); - if (!ptr || !*ptr) + if ((ret == -1) || !*ptr) return; DEBUG((int)level, ("tdb(%s): %s", tdb_name(tdb) ? tdb_name(tdb) : "unnamed", ptr)); @@ -867,11 +868,8 @@ static void tdb_wrap_log(TDB_CONTEXT *tdb, enum tdb_debug_level level, va_list ap; char *ptr = NULL; int debuglevel = 0; + int ret; - va_start(ap, format); - vasprintf(&ptr, format, ap); - va_end(ap); - switch (level) { case TDB_DEBUG_FATAL: debug_level = 0; @@ -889,7 +887,11 @@ static void tdb_wrap_log(TDB_CONTEXT *tdb, enum tdb_debug_level level, debuglevel = 0; } - if (ptr != NULL) { + va_start(ap, format); + ret = vasprintf(&ptr, format, ap); + va_end(ap); + + if (ret != -1) { const char *name = tdb_name(tdb); DEBUG(debuglevel, ("tdb(%s): %s", name ? name : "unnamed", ptr)); free(ptr); diff --git a/source3/libads/kerberos.c b/source3/libads/kerberos.c index d47e8a3ff1c..b37b9a500fb 100644 --- a/source3/libads/kerberos.c +++ b/source3/libads/kerberos.c @@ -407,8 +407,8 @@ static char *kerberos_secrets_fetch_salting_principal(const char *service, int e char *key = NULL; char *ret = NULL; - asprintf(&key, "%s/%s/enctype=%d", SECRETS_SALTING_PRINCIPAL, service, enctype); - if (!key) { + if (asprintf(&key, "%s/%s/enctype=%d", + SECRETS_SALTING_PRINCIPAL, service, enctype) == -1) { return NULL; } ret = (char *)secrets_fetch(key, NULL); @@ -438,7 +438,10 @@ static char* des_salt_key( void ) { char *key; - asprintf(&key, "%s/DES/%s", SECRETS_SALTING_PRINCIPAL, lp_realm()); + if (asprintf(&key, "%s/DES/%s", SECRETS_SALTING_PRINCIPAL, + lp_realm()) == -1) { + return NULL; + } return key; } @@ -609,9 +612,13 @@ bool kerberos_secrets_store_salting_principal(const char *service, return False; } if (strchr_m(service, '@')) { - asprintf(&princ_s, "%s", service); + if (asprintf(&princ_s, "%s", service) == -1) { + goto out; + } } else { - asprintf(&princ_s, "%s@%s", service, lp_realm()); + if (asprintf(&princ_s, "%s@%s", service, lp_realm()) == -1) { + goto out; + } } if (smb_krb5_parse_name(context, princ_s, &princ) != 0) { @@ -622,8 +629,9 @@ bool kerberos_secrets_store_salting_principal(const char *service, goto out; } - asprintf(&key, "%s/%s/enctype=%d", SECRETS_SALTING_PRINCIPAL, unparsed_name, enctype); - if (!key) { + if (asprintf(&key, "%s/%s/enctype=%d", + SECRETS_SALTING_PRINCIPAL, unparsed_name, enctype) + == -1) { goto out; } diff --git a/source3/librpc/ndr/ndr.c b/source3/librpc/ndr/ndr.c index 62a88a88562..53eff00d59c 100644 --- a/source3/librpc/ndr/ndr.c +++ b/source3/librpc/ndr/ndr.c @@ -176,12 +176,16 @@ _PUBLIC_ void ndr_print_debug_helper(struct ndr_print *ndr, const char *format, { va_list ap; char *s = NULL; - int i; + int i, ret; va_start(ap, format); - vasprintf(&s, format, ap); + ret = vasprintf(&s, format, ap); va_end(ap); + if (ret == -1) { + return; + } + for (i=0;idepth;i++) { DEBUGADD(0,(" ")); } @@ -450,11 +454,16 @@ _PUBLIC_ enum ndr_err_code ndr_pull_error(struct ndr_pull *ndr, { char *s=NULL; va_list ap; + int ret; va_start(ap, format); - vasprintf(&s, format, ap); + ret = vasprintf(&s, format, ap); va_end(ap); + if (ret == -1) { + return NDR_ERR_ALLOC; + } + DEBUG(3,("ndr_pull_error(%u): %s\n", ndr_err, s)); free(s); @@ -471,11 +480,16 @@ _PUBLIC_ enum ndr_err_code ndr_push_error(struct ndr_push *ndr, { char *s=NULL; va_list ap; + int ret; va_start(ap, format); - vasprintf(&s, format, ap); + ret = vasprintf(&s, format, ap); va_end(ap); + if (ret == -1) { + return NDR_ERR_ALLOC; + } + DEBUG(3,("ndr_push_error(%u): %s\n", ndr_err, s)); free(s); diff --git a/source3/librpc/ndr/ndr_basic.c b/source3/librpc/ndr/ndr_basic.c index 54397c9469b..f342c6e36f9 100644 --- a/source3/librpc/ndr/ndr_basic.c +++ b/source3/librpc/ndr/ndr_basic.c @@ -773,8 +773,7 @@ _PUBLIC_ void ndr_print_array_uint8(struct ndr_print *ndr, const char *name, ndr->depth++; for (i=0;idepth++; for (i=0;iparam_opt; } - asprintf(¶m_key, "%s:%s", type, option); - if (!param_key) { + if (asprintf(¶m_key, "%s:%s", type, option) == -1) { DEBUG(0,("asprintf failed!\n")); return NULL; } diff --git a/source3/passdb/machine_sid.c b/source3/passdb/machine_sid.c index d1599047a7b..8fafcbbbd46 100644 --- a/source3/passdb/machine_sid.c +++ b/source3/passdb/machine_sid.c @@ -128,7 +128,10 @@ static DOM_SID *pdb_generate_sam_sid(void) } /* check for an old MACHINE.SID file for backwards compatibility */ - asprintf(&fname, "%s/MACHINE.SID", lp_private_dir()); + if (asprintf(&fname, "%s/MACHINE.SID", lp_private_dir()) == -1) { + SAFE_FREE(sam_sid); + return NULL; + } if (read_sid_from_file(fname, sam_sid)) { /* remember it for future reference and unlink the old MACHINE.SID */