From 34b86155743f0ef1916bc3ae15907961c230c9ab Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 22 Aug 2010 14:47:22 +1000 Subject: pidl: cope with bad type conversions in unions This prevents a crash when converting bad types in NDR unions Pair-Programmed-With: Jelmer Vernooij --- pidl/lib/Parse/Pidl/Samba4/Python.pm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'pidl') diff --git a/pidl/lib/Parse/Pidl/Samba4/Python.pm b/pidl/lib/Parse/Pidl/Samba4/Python.pm index b7d70fafaf..f7968b4e0a 100644 --- a/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -986,7 +986,15 @@ sub ConvertObjectFromPythonLevel($$$$$$$$) } elsif ($l->{TYPE} eq "SWITCH") { $var_name = get_pointer_to($var_name); my $switch = ParseExpr($l->{SWITCH_IS}, $env, $e); - $self->assign($var_name, "py_export_" . GetNextLevel($e, $l)->{DATA_TYPE} . "($mem_ctx, $switch, $py_var)"); + my $switch_ptr = "$e->{NAME}_switch_$l->{LEVEL_INDEX}"; + $self->pidl("{"); + $self->indent; + $self->pidl("void *$switch_ptr;"); + $self->pidl("$switch_ptr = py_export_" . GetNextLevel($e, $l)->{DATA_TYPE} . "($mem_ctx, $switch, $py_var);"); + $self->pidl("if ($switch_ptr == NULL) { $fail }"); + $self->assign($var_name, "$switch_ptr"); + $self->deindent; + $self->pidl("}"); } elsif ($l->{TYPE} eq "SUBCONTEXT") { $self->ConvertObjectFromPythonLevel($env, $mem_ctx, $py_var, $e, GetNextLevel($e, $l), $var_name, $fail); } else { -- cgit