iconv_inconvenience and ndr_print_*

tridge at samba.org tridge at samba.org
Thu Jun 11 05:43:26 GMT 2009


Hi Jelmer,

The ndr_print_*() functions can end up calling string conversions via
ndr_size_*() functions which call ndr_push functions, which call
string conversion.

Unfortunately ndr_print_*() functions create their own "struct
ndr_print" structures, and don't setup ndr->iconv_convenience. So it
segfaults when the first structure with a string is run through a
ndr_size call.

My fix at the moment is below, but I suspect you may want a different
approach.

Cheers, Tridge


--- a/librpc/ndr/ndr.c
+++ b/librpc/ndr/ndr.c
@@ -218,6 +218,7 @@ _PUBLIC_ void ndr_print_debug(ndr_print_fn_t fn, const char *name, void *ptr)
 	ndr->print = ndr_print_debug_helper;
 	ndr->depth = 1;
 	ndr->flags = 0;
+	ndr->iconv_convenience = global_iconv_convenience;
 	fn(ndr, name, ptr);
 	talloc_free(ndr);
 }
@@ -236,6 +237,7 @@ _PUBLIC_ void ndr_print_union_debug(ndr_print_fn_t fn, const char *name, uint32_
 	ndr->print = ndr_print_debug_helper;
 	ndr->depth = 1;
 	ndr->flags = 0;
+	ndr->iconv_convenience = global_iconv_convenience;
 	ndr_print_set_switch_value(ndr, ptr, level);
 	fn(ndr, name, ptr);
 	talloc_free(ndr);
@@ -255,6 +257,7 @@ _PUBLIC_ void ndr_print_function_debug(ndr_print_function_t fn, const char *name
 	ndr->print = ndr_print_debug_helper;
 	ndr->depth = 1;
 	ndr->flags = 0;
+	ndr->iconv_convenience = global_iconv_convenience;
 	fn(ndr, name, flags, ptr);
 	talloc_free(ndr);
 }
@@ -276,6 +279,7 @@ _PUBLIC_ char *ndr_print_struct_string(TALLOC_CTX *mem_ctx, ndr_print_fn_t fn, c
 	ndr->print = ndr_print_string_helper;
 	ndr->depth = 1;
 	ndr->flags = 0;
+	ndr->iconv_convenience = global_iconv_convenience;
 	fn(ndr, name, ptr);
 	ret = talloc_steal(mem_ctx, (char *)ndr->private_data);
 failed:
@@ -300,6 +304,7 @@ _PUBLIC_ char *ndr_print_union_string(TALLOC_CTX *mem_ctx, ndr_print_fn_t fn, co
 	ndr->print = ndr_print_string_helper;
 	ndr->depth = 1;
 	ndr->flags = 0;
+	ndr->iconv_convenience = global_iconv_convenience;
 	ndr_print_set_switch_value(ndr, ptr, level);
 	fn(ndr, name, ptr);
 	ret = talloc_steal(mem_ctx, (char *)ndr->private_data);


More information about the samba-technical mailing list