Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perl_eval_{sv,pv} does not trap syntax errors #2380

Closed
p5pRT opened this issue Aug 16, 2000 · 7 comments
Closed

perl_eval_{sv,pv} does not trap syntax errors #2380

p5pRT opened this issue Aug 16, 2000 · 7 comments

Comments

@p5pRT
Copy link

@p5pRT p5pRT commented Aug 16, 2000

Migrated from rt.perl.org#3719 (status was 'resolved')

Searchable as RT3719$

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Aug 16, 2000

From @gisle

Created by gisle@aas.no

I have this application (actually Python) that embeds perl and calls
perl_eval_pv() to pass code to it. One problem with this is that
perl_eval_pv(code, FALSE) does not set ERRSV (aka $@​) on syntax
errors.

This is a little example program showing this behaviour​:

---------------------------------------------------------
#include <EXTERN.h>
#include <perl.h>

int main(int argc, char**argv, char**env)
{
  int i;
  char *embedding[] = {"", "-e", "0"};
  PerlInterpreter *my_perl = perl_alloc();
  perl_construct(my_perl);
  perl_parse(my_perl, NULL, 3, embedding, NULL);
  perl_run(my_perl);

  perl_eval_pv("sub { ", TRUE);
  /*** the program ought to abort here ***/

  if (SvTRUE(ERRSV))
  PerlIO_printf(Perl_debug_log, "XXX %s", SvPV_nolen(ERRSV));
  perl_eval_pv("1/0", TRUE);
  if (SvTRUE(ERRSV))
  PerlIO_printf(Perl_debug_log, "YYY %s", SvPV_nolen(ERRSV));
  /*** it aborts here ***/

  printf("done\n");
}

/*
  Compile with​: cc check-eval-syntax-error.c `perl -MExtUtils​::Embed -e ccopts -e ldopts`
*/
---------------------------------------------------------

This program prints​:

  $ ./a.out
  Illegal division by zero at (eval 2) line 2.

instead of something with "syntax error in (eval 1)".

Perl Info

Flags:
    category=core
    severity=low

Site configuration information for perl v5.6.0:

Configured by gisle at Mon May 22 17:07:41 CEST 2000.

Summary of my perl5 (revision 5.0 version 6 subversion 0) configuration:
  Platform:
    osname=linux, osvers=2.2.5, archname=i686-linux
    uname='linux eik 2.2.5 #1 mon sep 13 14:53:01 cest 1999 i686 unknown '
    config_args='-Dprefix=/local/perl/5.6.0_priv -Doptimize=-g -ders'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=undef d_sfio=undef uselargefiles=define 
    use64bitint=undef use64bitall=undef uselongdouble=undef usesocks=undef
  Compiler:
    cc='cc', optimize='-g', gccversion=egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
    cppflags='-DDEBUGGING -fno-strict-aliasing -I/usr/local/include'
    ccflags ='-DDEBUGGING -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'
    stdchar='char', d_stdstdio=define, usevfork=false
    intsize=4, longsize=4, ptrsize=4, doublesize=8
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -lndbm -lgdbm -ldbm -ldb -ldl -lm -lc -lposix -lcrypt
    libc=, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
    


@INC for perl v5.6.0:
    /local/perl/5.6.0_priv/lib/5.6.0/i686-linux
    /local/perl/5.6.0_priv/lib/5.6.0
    /local/perl/5.6.0_priv/lib/site_perl/5.6.0/i686-linux
    /local/perl/5.6.0_priv/lib/site_perl/5.6.0
    /local/perl/5.6.0_priv/lib/site_perl
    .


Environment for perl v5.6.0:
    HOME=/home/gisle
    LANG=POSIX
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=...
    PERL_BADLANG (unset)
    SHELL=/bin/bash


Loading

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Jul 26, 2010

From @gannett-ggreer

On Wed Aug 16 05​:18​:16 2000, gaas wrote​:

I have this application (actually Python) that embeds perl and calls
perl_eval_pv() to pass code to it. One problem with this is that
perl_eval_pv(code, FALSE) does not set ERRSV (aka $@​) on syntax
errors.

This is a little example program showing this behaviour​:

---------------------------------------------------------
#include <EXTERN.h>
#include <perl.h>

int main(int argc, char**argv, char**env)
{
int i;
char *embedding[] = {"", "-e", "0"};
PerlInterpreter *my_perl = perl_alloc();
perl_construct(my_perl);
perl_parse(my_perl, NULL, 3, embedding, NULL);
perl_run(my_perl);

perl_eval_pv("sub { ", TRUE);
/*** the program ought to abort here ***/

if (SvTRUE(ERRSV))
PerlIO_printf(Perl_debug_log, "XXX %s", SvPV_nolen(ERRSV));
perl_eval_pv("1/0", TRUE);
if (SvTRUE(ERRSV))
PerlIO_printf(Perl_debug_log, "YYY %s", SvPV_nolen(ERRSV));
/*** it aborts here ***/

printf("done\n");
}

/*
Compile with​: cc check-eval-syntax-error.c `perl -MExtUtils​::Embed
-e ccopts -e ldopts`
*/
---------------------------------------------------------

This program prints​:

$ ./a.out
Illegal division by zero at (eval 2) line 2.

instead of something with "syntax error in (eval 1)".

My embed-fu is weak, but it appears to be a simple fix.

http​://m-l.org/~perl/misc/0001-Fix-for-perl-3719-Preserve-for-perl_eval_pv-while-em.patch

http​://github.com/greerga/perl/commit/8ba06c38ccf1582a01143760851f9396c16b78f5

or attached.

--
George Greer

Loading

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Jul 26, 2010

From @gannett-ggreer

0001-Fix-for-perl-3719-Preserve-for-perl_eval_pv-while-em.patch
From 8ba06c38ccf1582a01143760851f9396c16b78f5 Mon Sep 17 00:00:00 2001
From: George Greer <perl@greerga.m-l.org>
Date: Sun, 25 Jul 2010 21:08:40 -0400
Subject: [PATCH] Fix for [perl #3719]: Preserve $@ for perl_eval_pv() while embedding.

Perl_eval_pv() wraps around Perl_eval_sv() but Perl_eval_sv() throws
away the error before Perl_eval_pv() can see it.
---
 perl.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/perl.c b/perl.c
index d52d79f..13076b1 100644
--- a/perl.c
+++ b/perl.c
@@ -2765,7 +2765,7 @@ Perl_eval_pv(pTHX_ const char *p, I32 croak_on_error)
 
     PERL_ARGS_ASSERT_EVAL_PV;
 
-    eval_sv(sv, G_SCALAR);
+    eval_sv(sv, G_SCALAR | G_KEEPERR);
     SvREFCNT_dec(sv);
 
     SPAGAIN;
-- 
1.7.0.4

Loading

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Sep 26, 2010

From @cpansprout

On Sun Jul 25 18​:18​:26 2010, greerga wrote​:

My embed-fu is weak,

So is mine.

but it appears to be a simple fix.

http​://m-l.org/~perl/misc/0001-Fix-for-perl-3719-Preserve-for-
perl_eval_pv-while-em.patch

http​://github.com/greerga/perl/commit/8ba06c38ccf1582a01143760851f9396c16b78f5

or attached.

Is anyone else able to review this?

Loading

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Sep 26, 2010

From @Leont

On Mon, Jul 26, 2010 at 3​:18 AM, George Greer via RT
<perlbug-followup@​perl.org> wrote​:

My embed-fu is weak, but it appears to be a simple fix.

http​://m-l.org/~perl/misc/0001-Fix-for-perl-3719-Preserve-for-perl_eval_pv-while-em.patch

http​://github.com/greerga/perl/commit/8ba06c38ccf1582a01143760851f9396c16b78f5

or attached.

Disclaimer​: I have embed-fu, but not so much internals-fu.

The G_KEEPERR flag seems to affect eval in at least 3 places
1) in doeval, right before compilation is tried.
2) in pp_leave, as the very last thing is does. I think this is only run on
3) in eval_sv, right after a successful eval.

I suspect this patch has a wider impact than intended. I don't really
know if that's really a problem though.

Also, the fact that this G_KEEPERR behavior of eval_sv is not
documented bothers me.

Leon

Loading

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Oct 3, 2010

From @iabyn

On Mon, Sep 27, 2010 at 12​:44​:16AM +0200, Leon Timmermans wrote​:

On Mon, Jul 26, 2010 at 3​:18 AM, George Greer via RT
<perlbug-followup@​perl.org> wrote​:

My embed-fu is weak, but it appears to be a simple fix.

http​://m-l.org/~perl/misc/0001-Fix-for-perl-3719-Preserve-for-perl_eval_pv-while-em.patch

http​://github.com/greerga/perl/commit/8ba06c38ccf1582a01143760851f9396c16b78f5

or attached.

Disclaimer​: I have embed-fu, but not so much internals-fu.

The G_KEEPERR flag seems to affect eval in at least 3 places
1) in doeval, right before compilation is tried.
2) in pp_leave, as the very last thing is does. I think this is only run on
3) in eval_sv, right after a successful eval.

I suspect this patch has a wider impact than intended. I don't really
know if that's really a problem though.

The patch is wrong, unfortunately. It only "works" in some circumstances
because it exploits another bug whereby G_KEEPERR still sets $@​ sometimes,

In particular​: under the original fix, if $@​ wasn't null when calling
eval_pv(pv,TRUE), it would croak, even if pv compiled and ran okay.

I've fixed the original bug with commit

  4aca2f6

and fixed the G_KEEPERR issue with

  6b2fb38

Also, the fact that this G_KEEPERR behavior of eval_sv is not
documented bothers me.

I've fixed that with

  be064c4

--
Thank God I'm an atheist.....

Loading

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Oct 3, 2010

@iabyn - Status changed from 'open' to 'resolved'

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant