perl-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stas Bekman <s...@stason.org>
Subject [patch] escape fmt strings
Date Mon, 28 Jan 2002 10:13:12 GMT

If I'm using undefined %size_string var in some test.pm I get this core:

#0  0x40307291 in strlen () from /lib/libc.so.6
#1  0x400300aa in apr_vformatter (flush_func=0x400308c0 <snprintf_flush>,
     vbuff=0xbfffd1e8,
     fmt=0x86c8478 "size_string\" requires explicit package name at 
/home/stas/apache.org/mp-util/t/response/TestAPR/date.pm line 
24.\nCompilation failed in require at (eval 10) line 3.\n", 
ap=0xbffff328) at apr_snprintf.c:944
#2  0x40030974 in apr_vsnprintf (buf=0xbfffd2d6 "Global symbol \"ÿÿÿ\032",
     len=8138,
     format=0x86c8468 "Global symbol \"%size_string\" requires explicit 
package name at /home/stas/apache.org/mp-util/t/response/TestAPR/date.pm 
line 24.\nCompilation failed in require at (eval 10) line 3.\n", 
ap=0xbffff328)
     at apr_snprintf.c:1235
#3  0x080b86c5 in log_error_core (file=0x403de598 "", line=255, level=3,
     status=0, s=0x835ccb8, r=0x8370a58, pool=0x0,
     fmt=0x86c8468 "Global symbol \"%size_string\" requires explicit 
package name at /home/stas/apache.org/mp-util/t/response/TestAPR/date.pm 
line 24.\nCompilation failed in require at (eval 10) line 3.\n", 
args=0xbffff328) at log.c:457
#4  0x080b8833 in ap_log_rerror (file=0x403de598 "", line=255, level=3,
     status=0, r=0x8370a58,
     fmt=0x86c8468 "Global symbol \"%size_string\" requires explicit 
package name at /home/stas/apache.org/mp-util/t/response/TestAPR/date.pm 
line 24.\nCompilation failed in require at (eval 10) line 3.\n") at 
log.c:511
#5  0x403d271b in modperl_errsv (my_perl=0x829d678, status=500, 
r=0x8370a58,
     s=0x835ccb8) at modperl_util.c:262

with error log:

[Mon Jan 28 16:53:28 2002] [error] Global symbol "¨òÿ¿ùa=@xÖôize_string" 
requires explicit package name at 
/home/stas/apache.org/mp-util/t/response/TestAPR/date.pm line 24.

so '... symbol \"%size_string\" requi...' gets passed as fmt down the
road. Therefore we need to espace fmt-unsafe chars.

I'm not sure whether this is the best way to solve this problem, but
consider this patch. (I've copied parts of the code from embedperl 
manpage). I'm not sure if this pattern string is complete though.

Index: src/modules/perl/modperl_util.c
===================================================================
RCS file: /home/cvs/modperl-2.0/src/modules/perl/modperl_util.c,v
retrieving revision 1.33
diff -u -r1.33 modperl_util.c
--- src/modules/perl/modperl_util.c	8 Jan 2002 01:29:23 -0000	1.33
+++ src/modules/perl/modperl_util.c	28 Jan 2002 10:03:43 -0000
@@ -1,5 +1,27 @@
  #include "mod_perl.h"

+void modperl_escape_fmt(pTHX_ SV **fmt)
+{
+    char* pattern = "s/\%(?!\%)/\%\%/g";
+
+    modperl_substitute(aTHX_ fmt, pattern);
+}
+
+void modperl_substitute(pTHX_ SV **string, char *pattern)
+{
+     SV *command = newSV(0);
+     STRLEN n_a;
+
+     sv_setpvf(command, "$string = '%s'; ($string =~ %s)",
+              SvPV(*string,n_a), pattern);
+
+     eval_sv(command, TRUE);
+     SvREFCNT_dec(command);
+
+     *string = get_sv("string", FALSE);
+}
+
+
  int modperl_require_module(pTHX_ const char *pv, int logfailure)
  {
      SV *sv;
@@ -251,6 +273,8 @@
              return status;
          }
  #endif
+        modperl_escape_fmt(aTHX_ &sv);
+
          if (r) {
              ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, SvPV(sv, n_a));
          }
Index: src/modules/perl/modperl_util.h
===================================================================
RCS file: /home/cvs/modperl-2.0/src/modules/perl/modperl_util.h,v
retrieving revision 1.31
diff -u -r1.31 modperl_util.h
--- src/modules/perl/modperl_util.h	14 Dec 2001 04:35:28 -0000	1.31
+++ src/modules/perl/modperl_util.h	28 Jan 2002 10:03:43 -0000
@@ -65,6 +65,14 @@

  int modperl_errsv(pTHX_ int status, request_rec *r, server_rec *s);

+/*
+ * substitute(string, pattern)
+ *
+ * Used for =~ operations that modify their left-hand side (s/// and tr///)
+ */
+void modperl_escape_fmt(pTHX_ SV **fmt);
+void modperl_substitute(pTHX_ SV **string, char *pattern);
+
  int modperl_require_module(pTHX_ const char *pv, int logfailure);
  int modperl_require_file(pTHX_ const char *pv, int logfailure);



_____________________________________________________________________
Stas Bekman             JAm_pH      --   Just Another mod_perl Hacker
http://stason.org/      mod_perl Guide   http://perl.apache.org/guide
mailto:stas@stason.org  http://ticketmaster.com http://apacheweek.com
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Mime
View raw message