diff options
author | Volker Lendecke <vl@samba.org> | 2021-01-24 15:14:58 +0100 |
---|---|---|
committer | Volker Lendecke <vl@samba.org> | 2021-01-28 16:58:35 +0000 |
commit | ce91a899a60059c9d495bf37ec5e3a8b4bf6afdc (patch) | |
tree | f35dd923fa05f39f0045446924692cf07c7ea130 | |
parent | 4df6c594c68dc5c2bfeb8e897f2226304da4848b (diff) | |
download | samba-ce91a899a60059c9d495bf37ec5e3a8b4bf6afdc.tar.gz |
librpc: Simplify dcerpc_binding_string()
Make it follow a more conventional memory handling style for reallocs.
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Samuel Cabrero <scabrero@samba.org>
-rw-r--r-- | librpc/rpc/binding.c | 121 |
1 files changed, 59 insertions, 62 deletions
diff --git a/librpc/rpc/binding.c b/librpc/rpc/binding.c index 7e20966b121..817498d8700 100644 --- a/librpc/rpc/binding.c +++ b/librpc/rpc/binding.c @@ -213,49 +213,50 @@ const char *epm_floor_string(TALLOC_CTX *mem_ctx, struct epm_floor *epm_floor) */ _PUBLIC_ char *dcerpc_binding_string(TALLOC_CTX *mem_ctx, const struct dcerpc_binding *b) { - char *s = talloc_strdup(mem_ctx, ""); - char *o = s; + char *s = NULL; + char *tmp = NULL; size_t i; const char *t_name = NULL; bool option_section = false; const char *target_hostname = NULL; + s = talloc_strdup(mem_ctx, ""); + if (s == NULL) { + goto nomem; + } + if (b->transport != NCA_UNKNOWN) { t_name = derpc_transport_string_by_transport(b->transport); if (!t_name) { - talloc_free(o); - return NULL; + goto nomem; } } if (!GUID_all_zero(&b->object)) { struct GUID_txt_buf buf; - o = s; - s = talloc_asprintf_append_buffer( + tmp = talloc_asprintf_append_buffer( s, "%s@", GUID_buf_string(&b->object, &buf)); - if (s == NULL) { - talloc_free(o); - return NULL; + if (tmp == NULL) { + goto nomem; } + s = tmp; } if (t_name != NULL) { - o = s; - s = talloc_asprintf_append_buffer(s, "%s:", t_name); - if (s == NULL) { - talloc_free(o); - return NULL; + tmp = talloc_asprintf_append_buffer(s, "%s:", t_name); + if (tmp == NULL) { + goto nomem; } + s = tmp; } if (b->host) { - o = s; - s = talloc_asprintf_append_buffer(s, "%s", b->host); - if (s == NULL) { - talloc_free(o); - return NULL; + tmp = talloc_asprintf_append_buffer(s, "%s", b->host); + if (tmp == NULL) { + goto nomem; } + s = tmp; } target_hostname = b->target_hostname; @@ -277,20 +278,18 @@ _PUBLIC_ char *dcerpc_binding_string(TALLOC_CTX *mem_ctx, const struct dcerpc_bi return s; } - o = s; - s = talloc_asprintf_append_buffer(s, "["); - if (s == NULL) { - talloc_free(o); - return NULL; + tmp = talloc_asprintf_append_buffer(s, "["); + if (tmp == NULL) { + goto nomem; } + s = tmp; if (b->endpoint) { - o = s; - s = talloc_asprintf_append_buffer(s, "%s", b->endpoint); - if (s == NULL) { - talloc_free(o); - return NULL; + tmp = talloc_asprintf_append_buffer(s, "%s", b->endpoint); + if (tmp == NULL) { + goto nomem; } + s = tmp; } for (i=0;i<ARRAY_SIZE(ncacn_options);i++) { @@ -298,61 +297,59 @@ _PUBLIC_ char *dcerpc_binding_string(TALLOC_CTX *mem_ctx, const struct dcerpc_bi continue; } - o = s; - s = talloc_asprintf_append_buffer(s, ",%s", ncacn_options[i].name); - if (s == NULL) { - talloc_free(o); - return NULL; + tmp = talloc_asprintf_append_buffer( + s, ",%s", ncacn_options[i].name); + if (tmp == NULL) { + goto nomem; } + s = tmp; } if (target_hostname) { - o = s; - s = talloc_asprintf_append_buffer(s, ",target_hostname=%s", - b->target_hostname); - if (s == NULL) { - talloc_free(o); - return NULL; + tmp = talloc_asprintf_append_buffer( + s, ",target_hostname=%s", b->target_hostname); + if (tmp == NULL) { + goto nomem; } + s = tmp; } if (b->target_principal) { - o = s; - s = talloc_asprintf_append_buffer(s, ",target_principal=%s", - b->target_principal); - if (s == NULL) { - talloc_free(o); - return NULL; + tmp = talloc_asprintf_append_buffer( + s, ",target_principal=%s", b->target_principal); + if (tmp == NULL) { + goto nomem; } + s = tmp; } if (b->assoc_group_id != 0) { - o = s; - s = talloc_asprintf_append_buffer(s, ",assoc_group_id=0x%08x", - b->assoc_group_id); - if (s == NULL) { - talloc_free(o); - return NULL; + tmp = talloc_asprintf_append_buffer( + s, ",assoc_group_id=0x%08x", b->assoc_group_id); + if (tmp == NULL) { + goto nomem; } + s = tmp; } for (i=0;b->options && b->options[i];i++) { - o = s; - s = talloc_asprintf_append_buffer(s, ",%s", b->options[i]); - if (s == NULL) { - talloc_free(o); - return NULL; + tmp = talloc_asprintf_append_buffer(s, ",%s", b->options[i]); + if (tmp == NULL) { + goto nomem; } + s = tmp; } - o = s; - s = talloc_asprintf_append_buffer(s, "]"); - if (s == NULL) { - talloc_free(o); - return NULL; + tmp = talloc_asprintf_append_buffer(s, "]"); + if (tmp == NULL) { + goto nomem; } + s = tmp; return s; +nomem: + TALLOC_FREE(s); + return NULL; } /* |