Browse files

- Put in safeguard to prevent attempted return of non-data types from

  R. Specific example from Hans-Jürgen Schönig was trying to return
  a closure (function pointer) as pg data type TEXT. This was causing
  an untrappable long jump within the R interpreter when trying
  to coerce it to character, resulting in a Postgres crash.
  At this point only allow return of these non-standard data types
  when the pg return type is BYTEA. That will allow them to be streamed
  to pg for storage which is about the only useful thing you could do
  with them anyway.
  • Loading branch information...
1 parent 42dd3b5 commit e436325461c916cb1794a820067f7f483c56981a @jconway committed Aug 21, 2011
Showing with 11 additions and 0 deletions.
  1. +11 −0 pg_conversion.c
@@ -680,6 +680,17 @@ r_get_pg(SEXP rval, plr_function *function, FunctionCallInfo fcinfo)
bool isnull = false;
Datum result;
+ if (function->result_typid != BYTEAOID &&
+ (TYPEOF(rval) == CLOSXP ||
+ TYPEOF(rval) == PROMSXP ||
+ TYPEOF(rval) == LANGSXP ||
+ TYPEOF(rval) == ENVSXP))
+ ereport(ERROR,
+ errmsg("incorrect function return type"),
+ errdetail("R return value type cannot be mapped to PostgreSQL return type."),
+ errhint("Try BYTEA as the PostgreSQL return type.")));
if (CALLED_AS_TRIGGER(fcinfo))
result = get_trigger_tuple(rval, function, fcinfo, &isnull);
else if (function->result_istuple || fcinfo->flinfo->fn_retset)

0 comments on commit e436325

Please sign in to comment.