Skip to content

Commit

Permalink
pidl:Python: check the return values of talloc_ptrtype()
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Metzmacher <[email protected]>
Reviewed-by: Andreas Schneider <[email protected]>
  • Loading branch information
metze-samba authored and cryptomilk committed Oct 26, 2016
1 parent ff947f2 commit b728c63
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pidl/lib/Parse/Pidl/Samba4/Python.pm
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,12 @@ sub PythonFunctionPackIn($$$)
my $val = "PyList_GET_SIZE($py_var)";
if ($e->{LEVELS}[0]->{TYPE} eq "POINTER") {
$self->pidl("r->in.$e->{NAME} = talloc_ptrtype(r, r->in.$e->{NAME});");
$self->pidl("if (r->in.$e->{NAME} == NULL) {");
$self->indent;
$self->pidl("PyErr_NoMemory();");
$self->pidl($fail);
$self->deindent;
$self->pidl("}");
$self->pidl("*r->in.$e->{NAME} = $val;");
} else {
$self->pidl("r->in.$e->{NAME} = $val;");
Expand Down Expand Up @@ -1239,9 +1245,21 @@ sub ConvertObjectFromPythonLevel($$$$$$$$)
# then this is where we would need to allocate it
if ($l->{POINTER_TYPE} eq "ref") {
$self->pidl("$var_name = talloc_ptrtype($mem_ctx, $var_name);");
$self->pidl("if ($var_name == NULL) {");
$self->indent;
$self->pidl("PyErr_NoMemory();");
$self->pidl($fail);
$self->deindent;
$self->pidl("}");
} elsif ($nl->{TYPE} eq "DATA" and Parse::Pidl::Typelist::is_scalar($nl->{DATA_TYPE})
and not Parse::Pidl::Typelist::scalar_is_reference($nl->{DATA_TYPE})) {
$self->pidl("$var_name = talloc_ptrtype($mem_ctx, $var_name);");
$self->pidl("if ($var_name == NULL) {");
$self->indent;
$self->pidl("PyErr_NoMemory();");
$self->pidl($fail);
$self->deindent;
$self->pidl("}");
} else {
$self->pidl("$var_name = NULL;");
}
Expand Down

0 comments on commit b728c63

Please sign in to comment.