Bill Allombert on Thu, 19 Feb 2004 14:57:37 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: catching execeptions of libpari the nice way


On Thu, Feb 19, 2004 at 02:29:04PM +0100, Prof. Dr. Nils-Peter Skoruppa wrote:
> Hi,
> We are currently setting up a sort of web server which
> uses the pari library to provide various numerical data on demand.
> Is there a reasonable way to catch exceptions of the pari library
> without having it exit the whole machinery ( and tearing down
> among others the server).
> For the moment I declared the
> static jmp_buf environnement
> from language/init.c in one of my files as extern (after commenting out
> the static, which crept in recently (?)) and put a setjmp( environnement)
> at an approptiate place in one of my own supplied routines.
> Though it seems to work (at least as interim solution
> while we are developping)
> I fear that this not what one is supposed/allowed to do.
> Of course I already looked into gp.c for finding an answer
> but, probably due to my ignorance, was unfortunately not able to pick up
> a "quick" answer.

As far as I understand, you should use the
CATCH() interface like in

static int
gegal_try(GEN x, GEN y)
{
  int i;
  CATCH(CATCH_ALL) {
    CATCH_RELEASE(); return 0;
  } TRY {
    i = gcmp0(gadd(x, gneg_i(y)));
  } ENDCATCH;
  return i;
}

This probably work only in the development version though.

However, I would like to warn you about the security implication of
allowing use of PARI to untrusted (remote) users. PARI is by no way
secure in this regard. Carefully crafted data/commands could lead to the
execution of arbitrary code, by exploiting bugs or incorrect
type-checking in the code.

Cheers,
Bill.