Git Product home page Git Product logo

juniper / libslax Goto Github PK

View Code? Open in Web Editor NEW
50.0 26.0 18.0 57 MB

libslax is a C implementation of the SLAX programming language, a dialect of XSLT that is more perl/C-like and easier to read/code/use. For additional information about SLAX, see

Home Page: https://github.com/Juniper/libslax/wiki

License: BSD 3-Clause "New" or "Revised" License

Shell 1.21% XSLT 11.79% C 75.36% Yacc 5.78% Makefile 3.57% M4 1.35% Roff 0.84% Perl 0.06% XS 0.03%

libslax's Introduction

libslax

Welcome to libslax, an implementation of the SLAX language, an alternate syntax for XSLT that follow the patterns of C and Perl. This library builds on the most excellent work of Daniel Veillard et al in the libxml2 and libxslt libraries, for which I heartily give thanks.

Check our github release page to find the latest release.

Please visit the libslax wiki. for more information, documentation, examples, and notes on SLAX and libslax.

<script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', ' UA-25845345-1']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script>

libslax's People

Contributors

ajhai avatar aruns16 avatar clemsonjeeper avatar dssatya avatar ganeshvs avatar philatjuniper avatar philshafer avatar pyvirus avatar ydnath avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

libslax's Issues

oxtradoc needs to handle xml2rfc v2 restrictions

As a general comment, oxtradoc needs to handle xml2rfc v2 restrictions. V2 was rewritten in python and is much nicer, but enforces restrictions that V1 did not.

anchors can't start with numeric

Andy Bierman writes:

draft-ietf-netconf-restconf-06.xml: Line 4849: Syntax of value for
attribute anchor of section is not valid

That line is:

So the xml2rfc-v2 doesn't like anchor identifiers that start
with numbers. Adding a leading "x" makes it work. I'll fix
oxtradoc to stop auto-generating these when the title starts
with a digit. The work-around is to add a manual anchor, like:

** 04 - 05 @D05@

tabs must be expanded

WARNING: Text around line 2588 contains tab characters. These will be expanded, assuming
a tab-size of 8.

A zillion of these can wreck your day. oxtradoc should expand tabs.

slax:sysctl fails for kern.cp_time

root@dent% cat /tmp/sc.slax
version 1.1;

param $name = "kern.cp_time";
param $type = "s";

match / {
{
expr slax:sysctl($name, $type);
}
}
root@dent% /usr/libexec/ui/slaxproc -E -n /tmp/sc.slax -a name kern.cp_time -a type i
308141824
root@dent% sysctl kern.cp_time
kern.cp_time: 308142554 0 40554495 11391848 724066967

So I only give access to the first integer value. Didn't
know about these arrays. I should use the same logic
as the sysctl command to turn anything into a string, if
the "s" is used. I'll open a bug for this.

Thanks,
Phil

Build issues under Ubuntu 14.04

Please consider adding the following requirements to the Building wiki page for Ubuntu:
Install:

  • build-essential
  • dh-autoreconf
  • libbison

Additionally, I get the following errors when running make:

scripthacker@ubuntu:~/.source/libslax/build$ make
Making all in libslax
make[1]: Entering directory `/home/scripthacker/.source/libslax/build/libslax'
make  all-am
make[2]: Entering directory `/home/scripthacker/.source/libslax/build/libslax'
  BISON  slaxparser.c
  BISON  slaxparser.h
  CC       jsonlexer.lo
  CC       jsonwriter.lo
  CC       slaxdebugger.lo
  CC       slaxdyn.lo
  CC       slaxext.lo
  CC       slaxio.lo
  CC       slaxlexer.lo
  CC       slaxloader.lo
  CC       slaxmvar.lo
  CC       slaxparser.lo
slaxparser.c: In function 'slaxParse':
slaxparser.c:2445:30: error: macro "yylex" requires 2 arguments, but only 1 given
       yychar = yylex (&yylval);
                              ^
slaxparser.c:2445:16: error: 'yylex' undeclared (first use in this function)
       yychar = yylex (&yylval);
                ^
slaxparser.c:2445:16: note: each undeclared identifier is reported only once for each function it appears in
make[2]: *** [slaxparser.lo] Error 1
make[2]: Leaving directory `/home/scripthacker/.source/libslax/build/libslax'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/home/scripthacker/.source/libslax/build/libslax'
make: *** [all-recursive] Error 1
scripthacker@ubuntu:~/.source/libslax/build$ 

Environment:
Linux ubuntu 3.13.0-36-generic #63-Ubuntu SMP Wed Sep 3 21:30:07 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

build fails on CentOS 6.4

[jeremy@ansible libslax-0.16.16]$ sh bin/setup.sh
Using autoreconf (GNU Autoconf) 2.63
configure.ac:30: warning: macro AM_PROG_AR' not found in library libtoolize: putting auxiliary files in.'.
libtoolize: copying file ./ltmain.sh' libtoolize:m4/libtool.m4' is newer: use --force' to overwrite libtoolize:m4/ltoptions.m4' is newer: use --force' to overwrite libtoolize:m4/ltversion.m4' is newer: use --force' to overwrite libtoolize:m4/lt~obsolete.m4' is newer: use --force' to overwrite configure.ac:30: warning: macroAM_PROG_AR' not found in library
configure.ac:30: error: possibly undefined macro: AM_PROG_AR
If this token and others are legitimate, please use m4_pattern_allow.
See the Autoconf documentation.
autoreconf: /usr/bin/autoconf failed with exit status: 1
Creating build directory ...
Setup is complete. To build libslax:
1) Type 'cd build ; ../configure' to configure libslax
2) Type 'make' to build libslax
3) Type 'make install' to install libslax
[jeremy@ansible libslax-0.16.16]$

0.16 breaking on Linux platforms (0.14 is fine)

Producible on Ubuntu 13.04, 12.04 LTS, and CentOS6.x (output is 12.04)

user@system:~/libslax-0.16.2$ diff libslax/slaxext.c ~/libslax-0.14.8/libslax/slaxext.c 
42d41
< #include <tzfile.h>
76,78c75,77
<  * Macosx issue: their version of c_name lacks the "const" and
<  * GCC nicks us for putting constant strings into a "char *".
<  * Somehow this works for <sys/syslog.h> but not for us....

---
>  * GCC nicks us for putting constant strings into a "char *" for
>  * MACOSX (which lackes the "const").  Somehow this works for
>  * <sys/syslog.h> but not for us.
96,100c95,96
< /*
<  * More macosx breakage: their version of LOG_MAKEPRI() does the "<<3"
<  * shift on fac values that are already shifted.
<  */
< #define LOG_MAKEPRI_REAL(fac, pri) ((fac) | (pri))

---
> /* More MACOSX breakage, where LOG_MAKEPRI() does the "<<3" shift */
> #define LOG_MAKEPRI2(fac, pri)   ((fac) | (pri))
894c890
<           tag[tlen] = '\0';

---
>           tag[tlen + 1] = '\0';
1749c1745
<     return (LOG_MAKEPRI_REAL(fac, sev));

---
>     return (LOG_MAKEPRI2(fac, sev));
1771c1767
<   return;

---
>   goto bail;
1847c1843
< slaxExtTimeCompare (const struct timeval *tvp, long secs)

---
> slaxExtTimeCompare (const struct timeval *tv, double limit)
1849c1845,1847
<     return (tvp->tv_sec < secs) ? TRUE : FALSE;

---
>     double t = tv->tv_sec + tv->tv_usec * USEC_PER_SEC;
> 
>     return (t < limit) ? TRUE : FALSE;
1873,1874c1871
<     int fd, rc, max;
<     long freq_in_secs;

---
>     int fd, rc, max, freq_int;
1888c1885
<     freq_in_secs = lrint(freq_double * SECSPERMIN);

---
>     freq_int = (int) floor(freq_double);
1892c1889
<     if (max <= 0 || freq_in_secs <= 0) {

---
>     if (max <= 0 || freq_int <= 0) {
1913c1910
<   if (old_fp == NULL) {

---
>   if (!old_fp) {
1934,1935d1930
<   if (old_fp)
<       fclose(old_fp);
1943,1944d1937
<   if (old_fp)
<       fclose(old_fp);
1975,1976c1968,1969
<             if (diff.tv_sec < freq_in_secs
<           || slaxExtTimeCompare(&diff, freq_in_secs)) {

---
>             if (diff.tv_sec < (freq_int * 60)
>           || slaxExtTimeCompare(&diff, freq_double)) {


make
make  all-recursive
make[1]: Entering directory `/home/death/libslax-0.16.2'
Making all in libslax
make[2]: Entering directory `/home/death/libslax-0.16.2/libslax'
  BUILD  slaxparser-xpl.y
  BUILD  slaxparser-out.y
  BISON  slaxparser.c
  CC     slaxdebugger.lo
  CC     slaxdyn.lo
  CC     slaxext.lo
slaxext.c:42:20: fatal error: tzfile.h: No such file or directory
compilation terminated.
make[2]: *** [slaxext.lo] Error 1
make[2]: Leaving directory `/home/death/libslax-0.16.2/libslax'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/death/libslax-0.16.2'
make: *** [all] Error 2

user@system:~/libslax-0.16.2$ apt-file search tzfile.h
elks-libc: /usr/lib/bcc/include/bsd/tzfile.h

A heap-buffer-overflow in slaxlexer.c:751:13

System info

Ubuntu X64, gcc (Ubuntu 5.5.0-12ubuntu1), slaxproc (latest master 45d88a)

Configure

CFLAGS="-g -fsanitize=address" LDFLAGS="-fsanitize=address" ./configure

Command line

./build/slaxproc/slaxproc -o /dev/null -x @@

AddressSanitizer output

=================================================================
==59937==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x625000002100 at pc 0x0000005671b1 bp 0x7fff6c8e6110 sp 0x7fff6c8e6108
READ of size 1 at 0x625000002100 thread T0
    #0 0x5671b0 in slaxIsCommentStart /home/seviezhou/libslax/build/libslax/../../libslax/slaxlexer.c:751:13
    #1 0x5671b0 in slaxLexer /home/seviezhou/libslax/build/libslax/../../libslax/slaxlexer.c:919
    #2 0x55f3a5 in slaxYylex /home/seviezhou/libslax/build/libslax/../../libslax/slaxlexer.c:1272:10
    #3 0x579c59 in slaxParse /home/seviezhou/libslax/build/libslax/slaxparser.c:2447:16
    #4 0x56df6e in slaxLoadFile /home/seviezhou/libslax/build/libslax/../../libslax/slaxloader.c:731:10
    #5 0x524b1e in do_slax_to_xslt /home/seviezhou/libslax/build/slaxproc/../../slaxproc/slaxproc.c:156:9
    #6 0x51f1d8 in main /home/seviezhou/libslax/build/slaxproc/../../slaxproc/slaxproc.c:1039:5
    #7 0x7efccb60f83f in __libc_start_main /build/glibc-e6zv40/glibc-2.23/csu/../csu/libc-start.c:291
    #8 0x41d818 in _start (/home/seviezhou/libslax/build/slaxproc/slaxproc+0x41d818)

0x625000002100 is located 0 bytes to the right of 8192-byte region [0x625000000100,0x625000002100)
allocated by thread T0 here:
    #0 0x4e1e90 in realloc /home/seviezhou/llvm-6.0.0/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:107
    #1 0x55daf3 in slaxGetInput /home/seviezhou/libslax/build/libslax/../../libslax/slaxlexer.c:601:14

SUMMARY: AddressSanitizer: heap-buffer-overflow /home/seviezhou/libslax/build/libslax/../../libslax/slaxlexer.c:751:13 in slaxIsCommentStart
Shadow bytes around the buggy address:
  0x0c4a7fff83d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c4a7fff83e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c4a7fff83f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c4a7fff8400: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c4a7fff8410: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c4a7fff8420:[fa]fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c4a7fff8430: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c4a7fff8440: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c4a7fff8450: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c4a7fff8460: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c4a7fff8470: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==59937==ABORTING

POC

heap-overflow-slaxIsCommentStart-slaxlexer-751.zip

Better error message for </tag>

SLAX doesn't use close tags, but users sometimes mistakenly do. A better error message is needed:

"data { ... }

Gives:

/Users/phil/zap/ddos-under-attack-juniper.txt:23: unexpected input: '{'; expected valid XPath expression
/Users/phil/zap/ddos-under-attack-juniper.txt:34: unexpected input: '}'; expected valid top-level statement

with statements must precede mode statements

This works:

    apply-templates {
	with $tag = $tag;
	with $x = @x;
	with $y = @y;
	with $indent = $indent;
	mode "line";
        }

This doesn't:

    apply-templates {
	mode "line";
	with $tag = $tag;
	with $x = @x;
	with $y = @y;
	with $indent = $indent;
        }

The error is especially useless:

pass2.slax:98: unexpected input: 'with'; expected close brace ('}')

The order of "sort", "with", and "mode" should not matter; libslax should handle any requirements that xslt has and keep the user isolated.

Thanks,
Phil

-fno-inline-functions-called-once is now an error on clang (OS X 10.10)

With the 10.10 preview and the updated clang the -fno-inline-functions-called-once is not a valid option and used to be just a warning, but now is a full error.

/Applications/Xcode.app/Contents/Developer/usr/bin/make  all-recursive
Making all in libslax
  CC       jsonwriter.lo
  CC       jsonlexer.lo
  CC       slaxdebugger.lo
  CC       slaxdyn.lo
clangclang: : errorerror: : unknown argument: '-fno-inline-functions-called-once' [-Wunused-command-line-argument-hard-error-in-future]unknown argument: '-fno-inline-functions-called-once' [-Wunused-command-line-argument-hard-error-in-future]

clang: error: unknown argument: '-fno-inline-functions-called-once' [-Wunused-command-line-argument-hard-error-in-future]
clangclang: : notenote: : this will be a hard error (cannot be downgraded to a warning) in the futurethis will be a hard error (cannot be downgraded to a warning) in the future

clang: note: this will be a hard error (cannot be downgraded to a warning) in the future
clang: error: unknown argument: '-fno-inline-functions-called-once' [-Wunused-command-line-argument-hard-error-in-future]
clang: note: this will be a hard error (cannot be downgraded to a warning) in the future
make[2]: *** [jsonwriter.lo] Error 1
make[2]: *** Waiting for unfinished jobs....
make[2]: *** [slaxdebugger.lo] Error 1
make[2]: *** [jsonlexer.lo] Error 1
make[2]: *** [slaxdyn.lo] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

Maybe need to check for clang in automake and make this an optional flag?

'make test' failing on Linux platforms

sudo make test
make[1]: Entering directory `/home/vagrant/libslax-0.16.14/tests'
make[2]: Entering directory `/home/vagrant/libslax-0.16.14/tests/core'
... test-authors-01.slax ...
... test-authors-02.slax ...
... test-authors-03.slax ...
... test-authors-04.slax ...
... test-authors-05.slax ...
... test-chassis-01.slax ...
... test-config-01.slax ...
... test-config-02.slax ...
... test-config-03.slax ...
... test-config-04.slax ...
... test-config-05.slax ...
... test-config-06.slax ...
... test-count-01.slax ...
... test-count-02.slax ...
... test-count-03.slax ...
... test-count-04.slax ...
+hit: one
+hit: two
+hit: three
+hit: four
+hit: five
... test-count-05.slax ...
... test-empty-01.slax ...
... test-empty-02.slax ...
... test-empty-03.slax ...
+compilation error: file ./test-empty-03.slax line 3 element include
+xsl:include : unable to load foo.slax
+compilation error: file ./test-empty-03.slax line 4 element import
+xsltParseStylesheetTop: ignoring misplaced import element
+slaxproc: 1 errors parsing script: './test-empty-03.slax'
... test-empty-04.slax ...
... test-empty-05.slax ...
... test-empty-06.slax ...
... test-empty-07.slax ...
... test-empty-08.slax ...
+compilation error: file ./test-empty-08.slax line 10 element some-new-feature
+xsltStylePreCompute: unknown xsl:some-new-feature
+some-new-feature not implemented
... test-empty-09.slax ...
... test-empty-10.slax ...
... test-empty-11.slax ...
... test-empty-12.slax ...
... test-empty-13.slax ...
... test-empty-14.slax ...
... test-empty-15.slax ...
... test-empty-16.slax ...
 <?xml version="1.0"?>
 <top>
   <back-reference>
-    <re1/>
+    <re1>
+      <match>a:a:a</match>
+      <match>a</match>
+    </re1>
     <re2/>
-    <re3/>
+    <re3>
+      <match>b:b:b</match>
+      <match>b</match>
+    </re3>
   </back-reference>
   <sequence>
     <i>1:1</i>
... test-empty-17.slax ...
... test-empty-18.slax ...
... test-empty-19.slax ...
... test-empty-20.slax ...
+done: 17
+done: 17
+done: 17
... test-empty-21.slax ...
... test-empty-22.slax ...
+this is a test
... test-empty-23.slax ...
... test-empty-24.slax ...
 <?xml version="1.0"?>
-<out>
-  <one>
-    <res>
-      <test>
-        <one>1</one>
-      </test>
-    </res>
-    <r2>
-      <a>
-        <b>
-          <c>
-            <test>
-              <one>1</one>
-            </test>
-          </c>
-        </b>
-      </a>
-    </r2>
-  </one>
-  <two>
-    <ores>&lt;test&gt;
-  &lt;one&gt;1&lt;/one&gt;
-&lt;/test&gt;</ores>
-    <or2>&lt;a&gt;
-  &lt;b&gt;
-    &lt;c&gt;
-      &lt;test&gt;
-        &lt;one&gt;1&lt;/one&gt;
-      &lt;/test&gt;
-    &lt;/c&gt;
-  &lt;/b&gt;
-&lt;/a&gt;</or2>
-  </two>
-  <three>
-    <xres>
-      <test>
-  <one>1</one>
-</test>
-    </xres>
-    <xr2>
-      <a>
-  <b>
-    <c>
-      <test>
-        <one>1</one>
-      </test>
-    </c>
-  </b>
-</a>
-    </xr2>
-  </three>
-</out>
+<out/>
+xmlXPathCompOpEval: function string-to-xml not found
+XPath error : Unregistered function
+runtime error: file ./test-empty-24.slax line 9 element variable
+Failed to evaluate the expression of variable 'res'.
... test-empty-25.slax ...
... test-empty-26.slax ...
... test-empty-27.slax ...
... test-empty-28.slax ...
 <?xml version="1.0"?>
 <out>
   <bit-set>
-    <a1>10001</a1>
-    <a2>11000</a2>
-    <a3>110000</a3>
-    <a4>100010000</a4>
+    <a1/>
   </bit-set>
-  <bit-clear>
-    <a1>11110</a1>
-    <a2>10111</a2>
-    <a3>011111</a3>
-    <a4>000011111</a4>
-  </bit-clear>
-  <bit-compare>
-    <a1>-1</a1>
-    <a2>1</a2>
-    <a3>1</a3>
-    <a4>0</a4>
-    <a5>1</a5>
-    <a6>-1</a6>
-    <a7>1</a7>
-  </bit-compare>
-  <bit-and>
-    <a1>00</a1>
-    <a2>100100</a2>
-    <a3>0000100</a3>
-    <a4>00001111</a4>
-    <a5>0000111</a5>
-    <a6>0000101</a6>
-    <a7>0010101</a7>
-    <a8>100001000</a8>
-    <a9>010111</a9>
-    <a10>00000000111111</a10>
-  </bit-and>
-  <bit-or>
-    <a1>11</a1>
-    <a2>101101</a2>
-    <a3>1010111</a3>
-    <a4>11111111</a4>
-    <a5>1111111</a5>
-    <a6>1111111</a6>
-    <a7>1111111</a7>
-    <a8>100001001</a8>
-    <a9>111111</a9>
-    <a10>10011101111111</a10>
-  </bit-or>
-  <bit-mask>
-    <a1>0</a1>
-    <a2>1</a2>
-    <a3>1111</a3>
-    <a4>00001111</a4>
-    <a5>00000000000000000000000011111111</a5>
-    <a6>1111111111</a6>
-    <a7>111</a7>
-    <a8>1111111</a8>
-    <a9>0000111</a9>
-    <a10>1111000</a10>
-  </bit-mask>
-  <ops>
-    <a1>21</a1>
-    <a2>1111111111111111</a2>
-    <a3>0000001111</a3>
-    <a4>0x15</a4>
-    <a5>1101000101</a5>
-  </ops>
 </out>
+xmlXPathCompOpEval: function set not found
+XPath error : Unregistered function
+xmlXPathCompiledEval: 1 objects left on the stack.
+runtime error: file ./test-empty-28.slax line 11 element value-of
+XPath evaluation returned no result.
... test-empty-29.slax ...
... test-empty-30.slax ...
+xsltApplySequenceConstructor: value-of was not compiled
... test-empty-31.slax ...
... test-empty-32.slax ...
+xmlXPathCompOpEval: function and not found
+XPath error : Unregistered function
+xmlXPathCompiledEval: 1 objects left on the stack.
+runtime error: file ./test-empty-32.slax line 7 element value-of
+XPath evaluation returned no result.
... test-empty-33.slax ...
... test-empty-34.slax ...
+work
... test-items-01.slax ...
... test-json-01.slax ...
 <top>
   <one>
     <input>{ a: 1, b: 2.5e-5 }</input>
-    <xml>
-      <my-top>
-        <a type="number">1</a>
-        <b type="number">2.5e-5</b>
-      </my-top>
-    </xml>
-    <back>{ "a": 1, "b": 2.5e-5 }
-</back>
   </one>
-  <two>
-    <input>[ 1, 2, 3, 4 ]</input>
-    <xml>
-      <my-top type="array">
-        <member type="number">1</member>
-        <member type="number">2</member>
-        <member type="number">3</member>
-        <member type="number">4</member>
-      </my-top>
-    </xml>
-    <back>[ 1, 2, 3, 4 ]
-</back>
-  </two>
-  <three>
-    <input>{ a: 1, b: [ 2, 3 ] }</input>
-    <xml>
-      <my-top>
-        <a type="number">1</a>
-        <b type="array">
-          <member type="number">2</member>
-          <member type="number">3</member>
-        </b>
-      </my-top>
-    </xml>
-    <back>{ "a": 1, "b": [ 2, 3 ] }
-</back>
-  </three>
-  <four>
-    <input>[ {a: 1}, {b: 2}, {c: 3} ]</input>
-    <xml>
-      <my-top type="array">
-        <member type="member">
-          <a type="number">1</a>
-        </member>
-        <member type="member">
-          <b type="number">2</b>
-        </member>
-        <member type="member">
-          <c type="number">3</c>
-        </member>
-      </my-top>
-    </xml>
-    <back>[ { "a": 1 }, { "b": 2 }, { "c": 3 } ]
-</back>
-  </four>
-  <five>
-    <input>{ a: "fish", b: "tur key", c: "mon key suit" }</input>
-    <xml>
-      <my-top>
-        <a>fish</a>
-        <b>tur key</b>
-        <c>mon key suit</c>
-      </my-top>
-    </xml>
-    <back>{ "a": "fish", "b": "tur key", "c": "mon key suit" }
-</back>
-  </five>
-  <six>
-    <input>   {
-      "Image": {
-          "Width":  800,
-          "Height": 600,
-          "Title":  "View from 15th Floor",
-          "Thumbnail": {
-              "Url":    "http://www.example.com/image/481989943",
-              "Height": 125,
-              "Width":  "100"
-          },
-          "IDs": [116, 943, 234, 38793]
-        }
-     }</input>
-    <xml>
-      <my-top>
-        <Image>
-          <Width type="number">800</Width>
-          <Height type="number">600</Height>
-          <Title>View from 15th Floor</Title>
-          <Thumbnail>
-            <Url>http://www.example.com/image/481989943</Url>
-            <Height type="number">125</Height>
-            <Width>100</Width>
-          </Thumbnail>
-          <IDs type="array">
-            <member type="number">116</member>
-            <member type="number">943</member>
-            <member type="number">234</member>
-            <member type="number">38793</member>
-          </IDs>
-        </Image>
-      </my-top>
-    </xml>
-    <back>{ "Image": { "Width": 800, "Height": 600, "Title": "View from 15th Floor", "Thumbnail": { "Url": "http://www.example.com/image/481989943", "Height": 125, "Width": "100" }, "IDs": [ 116, 943, 234, 38793 ] } }
-</back>
-  </six>
-  <seven>
-    <input>
-   [
-      {
-         "precision": "zip",
-         "Latitude":  37.7668,
-         "Longitude": -122.3959,
-         "Address":   "",
-         "City":      "SAN FRANCISCO",
-         "State":     "CA",
-         "Zip":       "94107",
-         "Country":   "US"
-      },
-      {
-         "precision": "zip",
-         "Latitude":  37.371991,
-         "Longitude": -122.026020,
-         "Address":   "",
-         "City":      "SUNNYVALE",
-         "State":     "CA",
-         "Zip":       "94085",
-         "Country":   "US"
-      }
-   ]
-</input>
-    <xml>
-      <my-top type="array">
-        <member type="member">
-          <precision>zip</precision>
-          <Latitude type="number">37.7668</Latitude>
-          <Longitude type="number">-122.3959</Longitude>
-          <Address></Address>
-          <City>SAN FRANCISCO</City>
-          <State>CA</State>
-          <Zip>94107</Zip>
-          <Country>US</Country>
-        </member>
-        <member type="member">
-          <precision>zip</precision>
-          <Latitude type="number">37.371991</Latitude>
-          <Longitude type="number">-122.026020</Longitude>
-          <Address></Address>
-          <City>SUNNYVALE</City>
-          <State>CA</State>
-          <Zip>94085</Zip>
-          <Country>US</Country>
-        </member>
-      </my-top>
-    </xml>
-    <back>[ { "precision": "zip", "Latitude": 37.7668, "Longitude": -122.3959, "Address": "", "City": "SAN FRANCISCO", "State": "CA", "Zip": "94107", "Country": "US" }, { "precision": "zip", "Latitude": 37.371991, "Longitude": -122.026020, "Address": "", "City": "SUNNYVALE", "State": "CA", "Zip": "94085", "Country": "US" } ]
-</back>
-  </seven>
-  <eight>
-    <input>[ { a: "nrt
-&#13;  nrt" } ]</input>
-    <xml>
-      <my-top type="array">
-        <member type="member">
-          <a>nrt
-&#13;  nrt</a>
-        </member>
-      </my-top>
-    </xml>
-    <back>[ { "a": "nrt\n\r\tnrt" } ]
-</back>
-  </eight>
-  <nine>
-    <input>{ "name": "Skip Tracer",
-              "location": "The city that never sleeps",
-              "age": 5,
-              "real": false,
-              "cases": null,
-              "equipment": [ "hat", "desk", "attitude" ]
-            }</input>
-    <xml>
-      <my-top>
-        <name>Skip Tracer</name>
-        <location>The city that never sleeps</location>
-        <age type="number">5</age>
-        <real type="false">false</real>
-        <cases type="null">null</cases>
-        <equipment type="array">
-          <member type="member">hat</member>
-          <member type="member">desk</member>
-          <member type="member">attitude</member>
-        </equipment>
-      </my-top>
-    </xml>
-    <back>{ "name": "Skip Tracer", "location": "The city that never sleeps", "age": 5, "real": false, "cases": null, "equipment": [ "hat", "desk", "attitude" ] }
-</back>
-  </nine>
-  <ten>
-    <input>{ "the  end": 1, "moment of truth": 2.5e-5, "3com": "dead" }</input>
-    <xml>
-      <my-top>
-        <element name="the&#9;end" type="number">1</element>
-        <element name="moment of truth" type="number">2.5e-5</element>
-        <element name="3com">dead</element>
-      </my-top>
-    </xml>
-    <back>{ "the\tend": 1, "moment of truth": 2.5e-5, "3com": "dead" }
-</back>
-  </ten>
 </top>
+xmlXPathCompOpEval: function json-to-xml not found
+XPath error : Unregistered function
+xmlXPathCompiledEval: 1 objects left on the stack.
+runtime error: file ./test-json-01.slax line 87 element variable
+Failed to evaluate the expression of variable 'x'.
... test-json-02.slax ...
+xmlXPathCompOpEval: function xml-to-json not found
+XPath error : Unregistered function
+runtime error: file ./test-json-02.slax line 10 element variable
+Failed to evaluate the expression of variable 'str'.
... test-list-01.slax ...
... test-list-02.slax ...
... test-list-03.slax ...
... test-lucy-01.slax ...
... test-player-01.slax ...
... test-sales-01.slax ...
... test-simple-01.slax ...
+compilation error: file ./test-simple-01.slax line 65 element number
+xsl:number : lang attribute not implemented
+Unimplemented block at ../../../libxslt/preproc.c:1461
+compilation error: file ./test-simple-01.slax line 65 element number
+xsl:number : letter-value 'alphabetic' not implemented
+Unimplemented block at ../../../libxslt/preproc.c:1470
+compilation error: file ./test-simple-01.slax line 109 element some-fancy-element
+xsltStylePreCompute: unknown xsl:some-fancy-element
+before
+This is 'one' is  good
... test-simple-02.slax ...
... test-simple-03.slax ...
... test-simple-04.slax ...
... test-simple-05.slax ...
... test-simple-06.slax ...
... test-simple-07.slax ...
... test-simple-08.slax ...
... test-simple-09.slax ...
... test-units-01.slax ...
make[2]: Leaving directory `/home/vagrant/libslax-0.16.14/tests/core'
make[2]: Entering directory `/home/vagrant/libslax-0.16.14/tests/bugs'
... pr422249.slax ...
... pr432942.slax ...
... pr497958.slax ...
make[2]: Leaving directory `/home/vagrant/libslax-0.16.14/tests/bugs'
make[2]: Entering directory `/home/vagrant/libslax-0.16.14/tests/errors'
... (skipping errors) ...
make[2]: Leaving directory `/home/vagrant/libslax-0.16.14/tests/errors'
make[1]: Leaving directory `/home/vagrant/libslax-0.16.14/tests'

A dynamic-stack-buffer-overflow in slaxlexer.c:955:4

System info

Ubuntu X64, gcc (Ubuntu 5.5.0-12ubuntu1), slaxproc (latest master 45d88a)

Configure

CFLAGS="-g -fsanitize=address" LDFLAGS="-fsanitize=address" ./configure

Command line

./build/slaxproc/slaxproc -o /dev/null -x @@

AddressSanitizer output

=================================================================
==36347==ERROR: AddressSanitizer: dynamic-stack-buffer-overflow on address 0x7fff6881f323 at pc 0x0000004e0985 bp 0x7fff6881f2f0 sp 0x7fff6881eaa0
WRITE of size 4 at 0x7fff6881f323 thread T0
    #0 0x4e0984 in __asan_memcpy /home/seviezhou/llvm-6.0.0/projects/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cc:23
    #1 0x5612b4 in slaxLexer /home/seviezhou/libslax/build/libslax/../../libslax/slaxlexer.c:955:4
    #2 0x55f3a5 in slaxYylex /home/seviezhou/libslax/build/libslax/../../libslax/slaxlexer.c:1272:10
    #3 0x579c59 in slaxParse /home/seviezhou/libslax/build/libslax/slaxparser.c:2447:16
    #4 0x56df6e in slaxLoadFile /home/seviezhou/libslax/build/libslax/../../libslax/slaxloader.c:731:10
    #5 0x524b1e in do_slax_to_xslt /home/seviezhou/libslax/build/slaxproc/../../slaxproc/slaxproc.c:156:9
    #6 0x51f1d8 in main /home/seviezhou/libslax/build/slaxproc/../../slaxproc/slaxproc.c:1039:5
    #7 0x7f7f0fd7883f in __libc_start_main /build/glibc-e6zv40/glibc-2.23/csu/../csu/libc-start.c:291
    #8 0x41d818 in _start (/home/seviezhou/libslax/build/slaxproc/slaxproc+0x41d818)

Address 0x7fff6881f323 is located in stack of thread T0
SUMMARY: AddressSanitizer: dynamic-stack-buffer-overflow /home/seviezhou/llvm-6.0.0/projects/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cc:23 in __asan_memcpy
Shadow bytes around the buggy address:
  0x10006d0fbe10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10006d0fbe20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10006d0fbe30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10006d0fbe40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10006d0fbe50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x10006d0fbe60: ca ca ca ca[03]cb cb cb cb cb cb cb 00 00 00 00
  0x10006d0fbe70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10006d0fbe80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10006d0fbe90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10006d0fbea0: f1 f1 f1 f1 00 f2 f2 f2 00 00 00 00 00 00 00 00
  0x10006d0fbeb0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==36347==ABORTING

POC

dynamic-stack-overflow-slaxLexer-slaxlexer-955.zip

imports must preceed includes (and anything else)

By the xslt spec, imports must preceed anything else, which is sort of stinky. SLAX needs to either live by that stinky rule (giving an error when broken), or handle it by moving imports to the appropriate spot in the tree.

need xml-to-slax extension function

Subrata Mazumdar writes:

Is there a programatic API in SLAX that would allow me to save data from XML format into SLAX?
I am looking for capability that can be achieved using "slaxproc -s -p".

No, I don't have that. But it's easy to add, as an extension
function that turns XML into a SLAX-friendly string, like:

var $s = xutil:xml-to-slax("<top><test/></top>");

where the output is " {\n ;\n}\n".

--expression

Add a --expression option to convert expression between SLAX and XPATH style:

% slaxproc --xslt-to-slax --expression "a or b"
a || b
% slaxproc --slax-to-xslt --expression "b || c"
b or c

Similar to --partial, but just for expressions. Different in that it wants an argument.

Perhaps a "--expression-on-stdin" option to make it read an expression from stdin.

insecure coded with 1, not 0

From Lamoni Finlayson:

I'm thinking it might have to do with libslax currently setting
CURLOPT_SSL_VERIFYHOST to 1 instead of 0.

From libslax's source for the "insecure" option:

curl_easy_setopt(curlp->ch_handle, CURLOPT_SSL_VERIFYHOST, 1L);

And from cURL docs:

When CURLOPT_SSL_VERIFYHOST
http://curl.haxx.se/libcurl/c/CURLOPT_SSL_VERIFYHOST.html is 2, that
certificate must indicate that the server is the server to which you meant
to connect, or the connection fails. Simply put, it means it has to have
the same name in the certificate as is in the URL you operate against.
Curl considers the server the intended one when the Common Name field or a
Subject Alternate Name field in the certificate matches the host name in
the URL to which you told Curl to connect.
When the verify value is 1, curl_easy_setopt will return an error and the
option value will not be changed. It was previously (in 7.28.0 and
earlier) a debug option of some sorts, but it is no longer supported due
to frequently leading to programmer mistakes. Future versions will stop
returning an error for 1 and just treat 1 and 2 the same.

Specifically this part is of interest:
"When the verify value is 1, curl_easy_setopt will return an error and the
option value will not be changed. It was previously (in 7.28.0 and
earlier) a debug option of some sorts, but it is no longer supported due
to frequently leading to programmer mistakes. Future versions will stop
returning an error for 1 and just treat 1 and 2 the same."

0.16 breaking on Linux platforms (0.14 is fine)

Producible on Ubuntu 13.04, 12.04 LTS, and CentOS6.x (output is 12.04)

user@system:~/libslax-0.16.2$ diff libslax/slaxext.c ~/libslax-0.14.8/libslax/slaxext.c
42d41
< #include <tzfile.h>
76,78c75,77
< * Macosx issue: their version of c_name lacks the "const" and
< * GCC nicks us for putting constant strings into a "char ".
< * Somehow this works for <sys/syslog.h> but not for us....
---
> * GCC nicks us for putting constant strings into a "char *" for
> * MACOSX (which lackes the "const"). Somehow this works for
> * <sys/syslog.h> but not for us.
96,100c95,96
< /

< * More macosx breakage: their version of LOG_MAKEPRI() does the "<<3"
< * shift on fac values that are already shifted.
< */
< #define LOG_MAKEPRI_REAL(fac, pri) ((fac) | (pri))
---
> /* More MACOSX breakage, where LOG_MAKEPRI() does the "<<3" shift */
> #define LOG_MAKEPRI2(fac, pri) ((fac) | (pri))
894c890
< tag[tlen] = '\0';
---
> tag[tlen + 1] = '\0';
1749c1745
< return (LOG_MAKEPRI_REAL(fac, sev));
---
> return (LOG_MAKEPRI2(fac, sev));
1771c1767
< return;
---
> goto bail;
1847c1843
< slaxExtTimeCompare (const struct timeval *tvp, long secs)
---
> slaxExtTimeCompare (const struct timeval *tv, double limit)
1849c1845,1847
< return (tvp->tv_sec < secs) ? TRUE : FALSE;
---
> double t = tv->tv_sec + tv->tv_usec * USEC_PER_SEC;
>
> return (t < limit) ? TRUE : FALSE;
1873,1874c1871
< int fd, rc, max;
< long freq_in_secs;
---
> int fd, rc, max, freq_int;
1888c1885
< freq_in_secs = lrint(freq_double * SECSPERMIN);
---
> freq_int = (int) floor(freq_double);
1892c1889
< if (max <= 0 || freq_in_secs <= 0) {
---
> if (max <= 0 || freq_int <= 0) {
1913c1910
< if (old_fp == NULL) {
---
> if (!old_fp) {
1934,1935d1930
< if (old_fp)
< fclose(old_fp);
1943,1944d1937
< if (old_fp)
< fclose(old_fp);
1975,1976c1968,1969
< if (diff.tv_sec < freq_in_secs
< || slaxExtTimeCompare(&diff, freq_in_secs)) {
---
> if (diff.tv_sec < (freq_int * 60)
> || slaxExtTimeCompare(&diff, freq_double)) {

make
make  all-recursive
make[1]: Entering directory `/home/death/libslax-0.16.2'
Making all in libslax
make[2]: Entering directory `/home/death/libslax-0.16.2/libslax'
  BUILD  slaxparser-xpl.y
  BUILD  slaxparser-out.y
  BISON  slaxparser.c
  CC     slaxdebugger.lo
  CC     slaxdyn.lo
  CC     slaxext.lo
slaxext.c:42:20: fatal error: tzfile.h: No such file or directory
compilation terminated.
make[2]: *** [slaxext.lo] Error 1
make[2]: Leaving directory `/home/death/libslax-0.16.2/libslax'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/death/libslax-0.16.2'
make: *** [all] Error 2

user@system:~/libslax-0.16.2$ apt-file search tzfile.h
elks-libc: /usr/lib/bcc/include/bsd/tzfile.h

mvar with document() fails to append

( Originally http://code.google.com/p/libslax/issues/detail?id=8 )

What steps will reproduce the problem?

  1. run "test-count-05.slax" test case

version 1.1;

var $last = document("test-count.xml");
mvar $one = $last/in;
mvar $two = $last/in/node();

match / {
{
{
{ copy-of $one; }
append $one += "one";
{ copy-of $one; }
}
{
{ copy-of $two; }
append $two += "one";
{ copy-of $two; }
}
}
}

What is the expected output? What do you see instead?

Neither of the append operations work.

Please use labels and text to provide additional information.

May 1, 2013 Delete comment
Project Member #1 phil.shafer

The is added to $slax-one, but not to $one:

(sdb) p $slax-one
node-set rtf-doc

1
2
3
4
5

one

(sdb) p $one
node-set

1
2
3
4
5

(sdb)

%jH and %jh for human-readable numbers

Add "%jH" and "%jh" to slax:printf(). Numbers would be formatting using logic that mirrors the -H and -h options for 'df':

 -H      "Human-readable" output.  Use unit suffixes: Byte, Kilobyte,
         Megabyte, Gigabyte, Terabyte and Petabyte in order to reduce the
         number of digits to three or less using base 10 for sizes.

 -h      "Human-readable" output.  Use unit suffixes: Byte, Kilobyte,
         Megabyte, Gigabyte, Terabyte and Petabyte in order to reduce the
         number of digits to three or less using base 2 for sizes.

Versions of libslax previous to this function would ignore these options.

A new function "slax:human-readable" would also be added to support this K/M/G/T/P conversion, with more options like "precision", "width", etc. along with the decimal-format values.

Facing issue while making make install

I wants to install util package in ./config iam giving path of my folder
./configure --host=toolchain_name --prefix=//usr/local afet that make executed but in doing make install following error i got Please can you help me to ressolve this peroblem.

test -z "/usr/yokel/libexec/gcc/i686-pc-linux-gnu/4.6.0" || /bin/mkdir -p "/usr/yokel/libexec/gcc/i686-pc-linux-gnu/4.6.0"
Installing dummy lib libgcj_bc.so.1.0.0
/home/dilbert/java/./gcc/cc1: error while loading shared libraries: libppl.so.9: cannot open shared object file: No such file or directory
make[5]: *** [install-exec-hook] Error 1
make[5]: Leaving directory /home/dilbert/java/i686-pc-linux-gnu/libjava' make[4]: *** [install-exec-am] Error 2 make[4]: Leaving directory/home/dilbert/java/i686-pc-linux-gnu/libjava'
make[3]: *** [install-am] Error 2
make[3]: Leaving directory /home/dilbert/java/i686-pc-linux-gnu/libjava' make[2]: *** [install-recursive] Error 1 make[2]: Leaving directory/home/dilbert/java/i686-pc-linux-gnu/libjava'
make[1]: *** [install-target-libjava] Error 2
make[1]: Leaving directory `/home/dilbert/java'
make: *** [install] Error 2

install fails on cygwin

Here is the last bit of output from ../configure:

checking the archiver (ar) interface... ar
checking whether ln -s works... yes
../configure: line 4202: syntax error near unexpected token `dlopen'
../configure: line 4202: `LT_INIT(dlopen shared)'

I've attached all the output from cygwin. I've installed all prerequisites, and then some. Just about anything that sounds like any of the required packages. It would be really great if someone could just provide a Windows binary so we wouldn't have to go through all this pain ;-)

temp.txt

XSL doesn't like double quotes and single quotes together in attributes

Jothivel S writes:

As Phil said,if a string has combination of single quotes and double quotes, it doesn't
work and if a string has only single quotes or only double quotes, then it works fine as
expected.

The fix would be to teach libslax to notice both quotes are in use
in a static string and use concat() to automagickally build a string
containing both quotes:

var $x = concat('"You', "can't", '", she said');

Lacking that, you'll need to resort to this trick by hand.

Thanks,
Phil

os:mkdir ignores EEXIST; should allow option to return error

The os:mkdir() function ignores the EEXIST error, since most scripts won't care about it. But some might, so I'll add a $options parameter, which can include an element to force an error in this case.

    var $options = {
        <error> "exists";
    }
    var $res = os:mkdir("/tmp", $opts);

need output-method json

(Originally http://code.google.com/p/libslax/issues/detail?id=10 )

When dealing with generating json, a script can use "output-method text;"
and use xutil:xml-to-json() to translate the output XML to JSON.

I'd like to make this a first-class output method. It would translate into <xsl:output method="text"/> but would turn on a flag that would call the internal version of xml-to-json() when the script is done.

libslax "extension" keyword has issues with already loaded libraries

libslax needs to notice if a library has been loaded already if the 'extension' keyword is used when defining a namespace.

the libjuise library is loaded twice when you use:

ns jcs extension = "http://xml.juniper.net/junos/commit-scripts/1.0";

in a script that is being ran through juise (which is already linked to libjuise). Therefore all the jsio_() settings are set (and lost) in the linked version of libjuise as opposed to the extension that is loaded a second time.

configure fails on Alpine Linux 3.3.3 (kernel 4.4.6)

Trying to install JUISE on Alpine Linux and running into issues running configure for libslax.

Error:

checking whether ln -s works... yes
../configure: ./configure.lineno: line 4201: syntax error: unexpected word (expecting ")")

Line 4201-4202:

# Must be after AC_PROG_AR   
LT_INIT(dlopen shared)

Alpine uses the musl libc (as opposed to glibc), which may be to blame. Additionally, it appears that Alpine uses PaX, which may also be causing issues with the build. Any pointers on a workaround?

Failure to make on Ubuntu 15.10

make returns:

Making all in libslax
make[1]: Entering directory '/home/daniel/libslax-0.20.1/build/libslax'
make all-am
make[2]: Entering directory '/home/daniel/libslax-0.20.1/build/libslax'
BUILD slaxparser-xpl.y
BUILD slaxparser-out.y
BISON slaxparser.c
CC jsonlexer.lo
../../libslax/jsonlexer.c: In function ‘slaxJsonFileToXml’:
../../libslax/jsonlexer.c:339:5: warning: implicit declaration of function ‘strlcpy’ [-Wimplicit-function-declaration]
strlcpy(sd.sd_filename, fname, sizeof(sd.sd_filename));
^
CC jsonwriter.lo
CC slaxdebugger.lo
In file included from ../../libslax/slaxdyn.h:15:0,
from ../../libslax/xmlsoft.h:26,
from ../../libslax/slaxinternals.h:24,
from ../../libslax/slaxdebugger.c:76:
../../libslax/slax.h:181:14: error: expected declaration specifiers or ‘...’ before numeric constant
__printflike(1, 2)
^
../../libslax/slax.h:181:17: error: expected declaration specifiers or ‘...’ before numeric constant
__printflike(1, 2)
^
../../libslax/slax.h:187:14: error: expected declaration specifiers or ‘...’ before numeric constant
__printflike(1, 2)
^
../../libslax/slax.h:187:17: error: expected declaration specifiers or ‘...’ before numeric constant
__printflike(1, 2)
^
../../libslax/slaxdebugger.c: In function ‘slaxDebugOutputXpath’:
../../libslax/slaxdebugger.c:392:2: warning: implicit declaration of function ‘slaxOutput’ [-Wimplicit-function-declaration]
slaxOutput("%s[boolean] %s", tag, xpath->boolval ? "true" : "false");
^
../../libslax/slaxdebugger.c: In function ‘slaxDebugTemplateInfo’:
../../libslax/slaxdebugger.c:721:2: warning: implicit declaration of function ‘strlcpy’ [-Wimplicit-function-declaration]
strlcpy(buf, "[global]", bufsiz);
^
Makefile:587: recipe for target 'slaxdebugger.lo' failed
make[2]: *** [slaxdebugger.lo] Error 1
make[2]: Leaving directory '/home/daniel/libslax-0.20.1/build/libslax'
Makefile:462: recipe for target 'all' failed
make[1]: *** [all] Error 2
make[1]: Leaving directory '/home/daniel/libslax-0.20.1/build/libslax'
Makefile:586: recipe for target 'all-recursive' failed
make: *** [all-recursive] Error 1

I've reinstalled all prerequisites, re-downloaded from repo, done some poking around on the internet in case anybody else has already handled this. No luck. Thanks for any help!

Add "percentage" info for "profile report" for code coverage numbers

When testing scripts, one wants to know that all (most) lines of the script have execised. The profile knows this information, and can easily know which lines are code (vs comments, blanks, etc) to know which lines need to count for coverage. The "Total" line can report this number.

Thanks,
Phil

%install section failing in 'bit' during package creation

For platforms with successful source builds (RPM + Deb), package compilation is failing at the %install portion under the 'bit' extension. Here's an example of Fedora 18. I'll supplement this issue with an attempted build under Ubuntu, but I believe this is the same exact area that it trips up.

This may be fixable with specfile options...

Making install in bit
make[2]: Entering directory `/home/vagrant/rpmbuild/BUILD/libslax-0.16.14/extensions/bit'
make[3]: Entering directory `/home/vagrant/rpmbuild/BUILD/libslax-0.16.14/extensions/bit'
 /bin/mkdir -p '/home/vagrant/rpmbuild/BUILDROOT/libslax-0.16.14-1.fc18.x86_64/usr/lib64/slax/extensions'
 /bin/sh ../../libtool   --mode=install /bin/install -c   libext_bit.la '/home/vagrant/rpmbuild/BUILDROOT/libslax-0.16.14-1.fc18.x86_64/usr/lib64/slax/extensions'
libtool: install: /bin/install -c .libs/libext_bit.lai /home/vagrant/rpmbuild/BUILDROOT/libslax-0.16.14-1.fc18.x86_64/usr/lib64/slax/extensions/libext_bit.la
libtool: install: /bin/install -c .libs/libext_bit.a /home/vagrant/rpmbuild/BUILDROOT/libslax-0.16.14-1.fc18.x86_64/usr/lib64/slax/extensions/libext_bit.a
libtool: install: chmod 644 /home/vagrant/rpmbuild/BUILDROOT/libslax-0.16.14-1.fc18.x86_64/usr/lib64/slax/extensions/libext_bit.a
libtool: install: ranlib /home/vagrant/rpmbuild/BUILDROOT/libslax-0.16.14-1.fc18.x86_64/usr/lib64/slax/extensions/libext_bit.a
libtool: install: warning: remember to run `libtool --finish /usr/lib64/slax/extensions'
/usr/bin/make  install-exec-hook
make[4]: Entering directory `/home/vagrant/rpmbuild/BUILD/libslax-0.16.14/extensions/bit'
sh: /usr/lib64/slax/extensions/libext_bit.la: No such file or directory
make[4]: *** [install-exec-hook] Error 1
make[4]: Leaving directory `/home/vagrant/rpmbuild/BUILD/libslax-0.16.14/extensions/bit'
make[3]: *** [install-exec-am] Error 2
make[3]: Leaving directory `/home/vagrant/rpmbuild/BUILD/libslax-0.16.14/extensions/bit'
make[2]: *** [install-am] Error 2
make[2]: Leaving directory `/home/vagrant/rpmbuild/BUILD/libslax-0.16.14/extensions/bit'
make[1]: *** [install-recursive] Error 1
make[1]: Leaving directory `/home/vagrant/rpmbuild/BUILD/libslax-0.16.14/extensions'
make: *** [install-recursive] Error 1
error: Bad exit status from /var/tmp/rpm-tmp.Mx77Ol (%install)


RPM build errors:
    Bad exit status from /var/tmp/rpm-tmp.Mx77Ol (%install)

A dynamic-stack-buffer-overflow in slaxproc.c:979:15

System info

Ubuntu X64, gcc (Ubuntu 5.5.0-12ubuntu1), slaxproc (latest master 45d88a)

Configure

CFLAGS="-g -fsanitize=address" LDFLAGS="-fsanitize=address" ./configure

Command line

run directly:

./build/slaxproc/slaxproc

AddressSanitizer output

=================================================================
==78506==ERROR: AddressSanitizer: dynamic-stack-buffer-overflow on address 0x7ffdea4fcfa0 at pc 0x00000051f888 bp 0x7ffdea4fcf70 sp 0x7ffdea4fcf68
WRITE of size 8 at 0x7ffdea4fcfa0 thread T0
    #0 0x51f887 in main /home/seviezhou/libslax/build/slaxproc/../../slaxproc/slaxproc.c:979:15
    #1 0x7fa14f44383f in __libc_start_main /build/glibc-e6zv40/glibc-2.23/csu/../csu/libc-start.c:291
    #2 0x41d818 in _start (/home/seviezhou/libslax/build/slaxproc/slaxproc+0x41d818)

Address 0x7ffdea4fcfa0 is located in stack of thread T0
SUMMARY: AddressSanitizer: dynamic-stack-buffer-overflow /home/seviezhou/libslax/build/slaxproc/../../slaxproc/slaxproc.c:979:15 in main
Shadow bytes around the buggy address:
  0x10003d4979a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10003d4979b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10003d4979c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10003d4979d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10003d4979e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x10003d4979f0: ca ca ca ca[01]cb cb cb cb cb cb cb 00 00 00 00
  0x10003d497a00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10003d497a10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10003d497a20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10003d497a30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10003d497a40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==78506==ABORTING

Infrastructure for warnings

Lots of non-fatal things can kill you.

Like having the wrong URI for a namespace. Your script looks fine, runs fine, but does not work.

Example:

ns xnm = "http://xml.juniper.net/xnm/1.1/xnm-oops!!";

...
    if (not(xnm:error)) {
       call destroy-the-world();
    }

Since xnm:error will never match, the world will be gone. Not good.

I think I can make this an optional warning, if that helps. The rule would go something like this:

When libslax sees a chunk of XML, it will looks for top-level 
namespaces whose prefixes match a prefix defined in a top-level
"ns" statement in the main script.

This will allow us to catch errors like your's but without searching the entire new XML document, which could be expensive.

I want to put this all inside a new "warning" infrastructure, so the user can say "-Wprefix-reuse" for this first scenario, -Wprefix-reuse-deep for complete namespace checking, -Wxxx for some future case, and "-Wall" checks these and other future warning flags.

The same logic can be applied to element names as well, so a script can report (after execution) any XML element names used in XPath expressions that were not seen during execution. Again, not check, but if you said "if (xnm:errror)", it would be a complete lifesaver.
Thanks,
Phil

libstax 0-21.x requires GCC 5 or later.

Hi,

I failed to compile this library (libstax-0-21.1) under xbuntu (in a VM) due to the following error:

Making all in libpsu
make[1]: Entering directory /home/rwilton/datastores-draft/libslax-0.21.0/build/libpsu' CC psualloc.lo CC psuasprintf.lo CC psubase64.lo CC psucpu.lo ../../libpsu/psucpu.c: In function ‘psu_cpu_get_info’: ../../libpsu/psucpu.c:108:5: error: inconsistent operand constraints in an ‘asm’ asm volatile ^ make[1]: *** [psucpu.lo] Error 1 make[1]: Leaving directory /home/rwilton/datastores-draft/libslax-0.21.0/build/libpsu'
make: *** [all-recursive] Error 1

After a bit of googling, it appears that this error is a known issue with my older gcc version:
gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3)

Updating to a version 5 of gcc fixed the problem:
gcc version 5.4.1 20160904 (Ubuntu 5.4.1-2ubuntu1~14.04)

Rob

0.16.X undefined reference to symbol 'dlclose@@GLIBC_2.2.5' - OS/Ubuntu 13.04/64

Ubuntu 13.04 64-bit (older Redhat and Debian-based building okay). This is happening on all 16.x releases (post recent patch to fix make issues)

death@death:/Documents/launchpad/libslax-0.16.7/build$ ./configure
-bash: ./configure: No such file or directory
death@death:
/Documents/launchpad/libslax-0.16.7/build$ ../configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking for ar... ar
checking the archiver (ar) interface... ar
checking whether ln -s works... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking how to print strings... printf
checking for a sed that does not truncate output... /bin/sed
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for fgrep... /bin/grep -F
checking for ld used by gcc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking the maximum length of command line arguments... 1572864
checking whether the shell understands some XSI constructs... yes
checking whether the shell understands "+="... yes
checking how to convert x86_64-unknown-linux-gnu file names to x86_64-unknown-linux-gnu format... func_convert_file_noop
checking how to convert x86_64-unknown-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /usr/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for archiver @file support... @
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking for sysroot... no
checking for mt... mt
checking if mt is a manifest tool... no
checking how to run the C preprocessor... gcc -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... no
checking for gcc option to produce PIC... -fPIC -DPIC
checking if gcc PIC flag -fPIC -DPIC works... yes
checking if gcc static flag -static works... yes
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... no
checking whether to build static libraries... yes
checking for basename... /usr/bin/basename
checking for bison... /usr/bin/bison
checking for cat... /bin/cat
checking for chmod... /bin/chmod
checking for cp... /bin/cp
checking for diff... /usr/bin/diff
checking for mkdir... /bin/mkdir
checking for mv... /bin/mv
checking for rm... /bin/rm
checking for sed... (cached) /bin/sed
checking for ANSI C header files... (cached) yes
checking for inline... inline
checking for size_t... yes
checking for working alloca.h... yes
checking for alloca... yes
checking for stdlib.h... (cached) yes
checking for GNU libc compatible malloc... yes
checking for stdlib.h... (cached) yes
checking for GNU libc compatible realloc... yes
checking for bzero... yes
checking for memmove... yes
checking for strchr... yes
checking for strcspn... yes
checking for strerror... yes
checking for strspn... yes
checking for sranddev... no
checking for srand... yes
checking for strlcpy... no
checking for fdopen... yes
checking for getrusage... yes
checking for gettimeofday... yes
checking for ctime... yes
checking for getpass... yes
checking for sysctlbyname... no
checking for flock... yes
checking for asprintf... yes
checking for dlfcn.h... (cached) yes
checking tzfile.h usability... no
checking tzfile.h presence... no
checking for tzfile.h... no
checking for dlfunc... no
checking sys/time.h usability... yes
checking sys/time.h presence... yes
checking for sys/time.h... yes
checking ctype.h usability... yes
checking ctype.h presence... yes
checking for ctype.h... yes
checking errno.h usability... yes
checking errno.h presence... yes
checking for errno.h... yes
checking stdio.h usability... yes
checking stdio.h presence... yes
checking for stdio.h... yes
checking for stdlib.h... (cached) yes
checking for string.h... (cached) yes
checking sys/param.h usability... yes
checking sys/param.h presence... yes
checking for sys/param.h... yes
checking for unistd.h... (cached) yes
checking sys/sysctl.h usability... yes
checking sys/sysctl.h presence... yes
checking for sys/sysctl.h... yes
checking for xmlNewParserCtxt in -lxml2... yes
checking for xsltInit in -lxslt... yes
checking whether to build with warnings... no
checking whether to build with debugging... no
checking whether to build with readline... no
checking whether to build with libedit... no
checking whether to build with printflike... no
checking for libxml libraries >= 2.7.7... 2.9.0 found
checking for libxslt libraries >= 1.1.26... 1.1.27 found
checking for libcurl libraries >= 7.21.3... libcurl 7.29.0 found
checking for stat.st_mtimespec... no
Using configure dir /home/death/Documents/launchpad/libslax-0.16.7
configure: creating ./config.status
config.status: creating Makefile
config.status: creating slax-config
config.status: creating libslax/Makefile
config.status: creating libslax/slaxconfig.h
config.status: creating extensions/Makefile
config.status: creating extensions/bit/Makefile
config.status: creating extensions/curl/Makefile
config.status: creating extensions/xutil/Makefile
config.status: creating extensions/os/Makefile
config.status: creating slaxproc/Makefile
config.status: creating tests/Makefile
config.status: creating tests/core/Makefile
config.status: creating tests/bugs/Makefile
config.status: creating tests/errors/Makefile
config.status: creating tests/libxslt/Makefile
config.status: creating bin/Makefile
config.status: creating doc/Makefile
config.status: creating doc/oxtradoc/oxtradoc
config.status: creating libslax.pc
config.status: creating libslax.spec
config.status: creating config.h
config.status: config.h is unchanged
config.status: executing depfiles commands
config.status: executing libtool commands
/bin/rm: cannot remove 'libtoolT': No such file or directory
configure: summary of build options:

libslax version: 0.16.7
host type: x86_64-unknown-linux-gnu / linux-gnu
install prefix: /usr/local
srcdir: ..
libdir: ${exec_prefix}/lib
bindir: /usr/local/bin
includedir: ${prefix}/include
extensions dir: ${exec_prefix}/lib/slax/extensions

compiler: gcc
compiler flags: -D_GNU_SOURCE -g -O2
library types: Shared=no, Static=yes
libxml version: 2.9.0
libxslt cflags: -I/usr/include/libxml2
libxml libs: -lxml2
libxslt version: 1.1.27
libxslt cflags: -I/usr/include/libxml2
libxslt libs: -lxslt -lxml2
libcurl version: libcurl 7.29.0
libcurl cflags:
libcurl libs: -L/usr/lib/x86_64-linux-gnu -lcurl

warnings: no
debug: no
readline: no
libedit: no
printf-like: no
libxslt tests: no

death@death:~/Documents/launchpad/libslax-0.16.7/build$ make
make all-recursive
make[1]: Entering directory /home/death/Documents/launchpad/libslax-0.16.7/build' Making all in libslax make[2]: Entering directory/home/death/Documents/launchpad/libslax-0.16.7/build/libslax'
CC slaxdebugger.lo
CC slaxdyn.lo
CC slaxext.lo
CC slaxio.lo
CC slaxlexer.lo
CC slaxloader.lo
CC slaxmvar.lo
CC slaxparser.lo
CC slaxprofiler.lo
CC slaxstring.lo
CC slaxtree.lo
CC slaxwriter.lo
CCLD libslax.la
make[2]: Leaving directory /home/death/Documents/launchpad/libslax-0.16.7/build/libslax' Making all in extensions make[2]: Entering directory/home/death/Documents/launchpad/libslax-0.16.7/build/extensions'
Making all in bit
make[3]: Entering directory /home/death/Documents/launchpad/libslax-0.16.7/build/extensions/bit' CC ext_bit.lo CCLD libext_bit.la make[3]: Leaving directory/home/death/Documents/launchpad/libslax-0.16.7/build/extensions/bit'
Making all in curl
make[3]: Entering directory /home/death/Documents/launchpad/libslax-0.16.7/build/extensions/curl' CC ext_curl.lo CCLD libext_curl.la make[3]: Leaving directory/home/death/Documents/launchpad/libslax-0.16.7/build/extensions/curl'
Making all in xutil
make[3]: Entering directory /home/death/Documents/launchpad/libslax-0.16.7/build/extensions/xutil' CC ext_xutil.lo CC jsonparser.lo CC jsonlexer.lo CC jsonwriter.lo CCLD libext_xutil.la make[3]: Leaving directory/home/death/Documents/launchpad/libslax-0.16.7/build/extensions/xutil'
Making all in os
make[3]: Entering directory /home/death/Documents/launchpad/libslax-0.16.7/build/extensions/os' CC ext_os.lo CCLD libext_os.la make[3]: Leaving directory/home/death/Documents/launchpad/libslax-0.16.7/build/extensions/os'
make[3]: Entering directory /home/death/Documents/launchpad/libslax-0.16.7/build/extensions' make[3]: Nothing to be done forall-am'.
make[3]: Leaving directory /home/death/Documents/launchpad/libslax-0.16.7/build/extensions' make[2]: Leaving directory/home/death/Documents/launchpad/libslax-0.16.7/build/extensions'
Making all in slaxproc
make[2]: Entering directory /home/death/Documents/launchpad/libslax-0.16.7/build/slaxproc' CC slaxproc.o CCLD slaxproc /usr/bin/ld: /home/death/Documents/launchpad/libslax-0.16.7/build/libslax/.libs/libslax.a(slaxdyn.o): undefined reference to symbol 'dlclose@@GLIBC_2.2.5' /usr/bin/ld: note: 'dlclose@@GLIBC_2.2.5' is defined in DSO /lib/x86_64-linux-gnu/libdl.so.2 so try adding it to the linker command line /lib/x86_64-linux-gnu/libdl.so.2: could not read symbols: Invalid operation collect2: error: ld returned 1 exit status make[2]: *** [slaxproc] Error 1 make[2]: Leaving directory/home/death/Documents/launchpad/libslax-0.16.7/build/slaxproc'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/death/Documents/launchpad/libslax-0.16.7/build'
make: *** [all] Error 2

add wall-clock time to profiler output

The output of sdb's profiler does not show wall-clock time, which is important for sub-processes (e.g. when jcs:execute spawns ssh). Adding this will help users understand where time is going.

Can't compile on Arch Linux, got Lex errors

slaxparser-out.y:283:17: error: conflicting types for 'slaxParse'
#define yyparse slaxParse
^
slaxparser.c:2257:1: note: in expansion of macro 'yyparse'
yyparse (void)
^
In file included from ../../libslax/slaxinternals.h:33:0,
from slaxparser-out.y:274:
../../libslax/slaxlexer.h:164:1: note: previous declaration of 'slaxParse' was here
slaxParse (slax_data_t _);
^
slaxparser.c: In function 'slaxParse':
slaxparser.c:2426:30: error: macro "yylex" requires 2 arguments, but only 1 given
yychar = yylex (&yylval);
^
slaxparser.c:2426:16: error: 'yylex' undeclared (first use in this function)
yychar = yylex (&yylval);
^
slaxparser.c:2426:16: note: each undeclared identifier is reported only once for each function it appears in
slaxparser-out.y:302:40: error: 'slax_data' undeclared (first use in this function)
#define STACK_CLEAR(_x) slaxStackClear(slax_data, &(x), yyvsp)
^
slaxparser-out.y:346:17: note: in expansion of macro 'STACK_CLEAR'
{ $$ = STACK_CLEAR($1); }
^
make[2]: *
* [slaxparser.lo] Error 1
make[2]: Leaving directory /run/shm/libslax/build/libslax' make[1]: *** [all-recursive] Error 1 make[1]: Leaving directory/run/shm/libslax/build'
make: *** [all] Error 2

A heap-buffer-overflow in slaxlexer.c:986:11

System info

Ubuntu X64, gcc (Ubuntu 5.5.0-12ubuntu1), slaxproc (latest master 45d88a)

Configure

CFLAGS="-g -fsanitize=address" LDFLAGS="-fsanitize=address" ./configure

Command line

./build/slaxproc/slaxproc -o /dev/null -x @@

AddressSanitizer output

=================================================================
==54185==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x625000002100 at pc 0x0000005661fa bp 0x7fff21d66b10 sp 0x7fff21d66b08
READ of size 1 at 0x625000002100 thread T0
    #0 0x5661f9 in slaxLexer /home/seviezhou/libslax/build/libslax/../../libslax/slaxlexer.c:986:11
    #1 0x55f3a5 in slaxYylex /home/seviezhou/libslax/build/libslax/../../libslax/slaxlexer.c:1272:10
    #2 0x579c59 in slaxParse /home/seviezhou/libslax/build/libslax/slaxparser.c:2447:16
    #3 0x56df6e in slaxLoadFile /home/seviezhou/libslax/build/libslax/../../libslax/slaxloader.c:731:10
    #4 0x524b1e in do_slax_to_xslt /home/seviezhou/libslax/build/slaxproc/../../slaxproc/slaxproc.c:156:9
    #5 0x51f1d8 in main /home/seviezhou/libslax/build/slaxproc/../../slaxproc/slaxproc.c:1039:5
    #6 0x7f8c06e7f83f in __libc_start_main /build/glibc-e6zv40/glibc-2.23/csu/../csu/libc-start.c:291
    #7 0x41d818 in _start (/home/seviezhou/libslax/build/slaxproc/slaxproc+0x41d818)

0x625000002100 is located 0 bytes to the right of 8192-byte region [0x625000000100,0x625000002100)
allocated by thread T0 here:
    #0 0x4e1e90 in realloc /home/seviezhou/llvm-6.0.0/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:107
    #1 0x55daf3 in slaxGetInput /home/seviezhou/libslax/build/libslax/../../libslax/slaxlexer.c:601:14

SUMMARY: AddressSanitizer: heap-buffer-overflow /home/seviezhou/libslax/build/libslax/../../libslax/slaxlexer.c:986:11 in slaxLexer
Shadow bytes around the buggy address:
  0x0c4a7fff83d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c4a7fff83e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c4a7fff83f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c4a7fff8400: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c4a7fff8410: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c4a7fff8420:[fa]fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c4a7fff8430: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c4a7fff8440: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c4a7fff8450: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c4a7fff8460: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c4a7fff8470: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==54185==ABORTING

POC

heap-overflow-slaxLexer-slaxlexer-986.zip

terminate inside slax:while leads to infinite loop

The following code:

version 1.2;

match / {
    <op-script-results> {
        while ( true() ) {
            terminate "doa";
        }
    }
}

turns into:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:slax="http://xml.libslax.org/slax" version="1.0" extension-element-prefixes="slax">
  <xsl:template match="/">
    <op-script-results>
      <slax:while xmlns:slax="http://xml.libslax.org/slax" test="true()">
        <xsl:message terminate="yes">doa</xsl:message>
      </slax:while>
    </op-script-results>
  </xsl:template>
</xsl:stylesheet>

It's processing the terminate, but then it continues
to "skip" over the rest of the entries, thinking that it's a set
of nodes instead of a condition. So it really, really, quickly
loops forever. slax:while needs to notice the libxslt terminate flag.

lookahead (for function parsing) isn't looking far enough

The XPath rules for functions require lookahead:

http://www.w3.org/TR/xpath/#exprlex

If the character following an NCName (possibly after intervening ExprWhitespace) is (, then the token must be recognized as a NodeType or a FunctionName.

libslax does not handle the case when the whitespace contains a newline:

Bock [slax/libslax]% build/slaxproc/slaxproc --format > /dev/null
version 1.1;
var $x = concat(a,b);
Bock [slax/libslax]% build/slaxproc/slaxproc --format > /dev/null
version 1.1;
var $x = concat
(a,b);
-:3: unexpected input: '('; expected semi-colon (';')
-: 1 error detected during parsing (0)
slaxproc: cannot parse file: '-'
Bock [slax/libslax]% build/slaxproc/slaxproc --format > /dev/null
version 1.1;
var $x = concat (a,b);
Bock [slax/libslax]%

The first and third case work correctly, but the second, where a newline is present, does not.

Thanks,
Phil

Ubuntu 12.04 - slaxproc: error while loading shared libraries: libslax.so.0: cannot open shared object file: No such file or directory

Hi Guys,

I am having some trouble with building libslax. On CENTOS, I couldn't get a new enough version of libcurl. On Ubuntu 12.04, I can build it but I can't open the shared object.

fluong@ubuntu:/Downloads/libslax-0.17.1$ which slaxproc
/usr/local/bin/slaxproc
fluong@ubuntu:
/Downloads/libslax-0.17.1$ slaxproc --versin
slaxproc: error while loading shared libraries: libslax.so.0: cannot open shared object file: No such file or directory
fluong@ubuntu:/Downloads/libslax-0.17.1$ ls /usr/local/lib
libjuise.a libjuise.so libjuise.so.0.0.0 libslax.la libslax.so.0 pkgconfig slax
libjuise.la libjuise.so.0 libslax.a libslax.so libslax.so.0.0.0 python2.7
fluong@ubuntu:
/Downloads/libslax-0.17.1$

I could use some help or suggestions.

Thanks,

Franco

A Segmentation fault in slaxlexer.c:1107:13

System info

Ubuntu X64, gcc (Ubuntu 5.5.0-12ubuntu1), slaxproc (latest master 45d88a)

Configure

CFLAGS="-g -fsanitize=address" LDFLAGS="-fsanitize=address" ./configure

Command line

./build/slaxproc/slaxproc -o /dev/null -x @@

AddressSanitizer output

=================================================================
==38438==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x625000002100 at pc 0x000000567501 bp 0x7ffc5b95d2f0 sp 0x7ffc5b95d2e8
READ of size 1 at 0x625000002100 thread T0
    #0 0x567500 in slaxLexer /home/seviezhou/libslax/build/libslax/../../libslax/slaxlexer.c:1107:13
    #1 0x55f3a5 in slaxYylex /home/seviezhou/libslax/build/libslax/../../libslax/slaxlexer.c:1272:10
    #2 0x579c59 in slaxParse /home/seviezhou/libslax/build/libslax/slaxparser.c:2447:16
    #3 0x56df6e in slaxLoadFile /home/seviezhou/libslax/build/libslax/../../libslax/slaxloader.c:731:10
    #4 0x524b1e in do_slax_to_xslt /home/seviezhou/libslax/build/slaxproc/../../slaxproc/slaxproc.c:156:9
    #5 0x51f1d8 in main /home/seviezhou/libslax/build/slaxproc/../../slaxproc/slaxproc.c:1039:5
    #6 0x7f8c73f1483f in __libc_start_main /build/glibc-e6zv40/glibc-2.23/csu/../csu/libc-start.c:291
    #7 0x41d818 in _start (/home/seviezhou/libslax/build/slaxproc/slaxproc+0x41d818)

0x625000002100 is located 0 bytes to the right of 8192-byte region [0x625000000100,0x625000002100)
allocated by thread T0 here:
    #0 0x4e1e90 in realloc /home/seviezhou/llvm-6.0.0/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:107
    #1 0x55daf3 in slaxGetInput /home/seviezhou/libslax/build/libslax/../../libslax/slaxlexer.c:601:14

SUMMARY: AddressSanitizer: heap-buffer-overflow /home/seviezhou/libslax/build/libslax/../../libslax/slaxlexer.c:1107:13 in slaxLexer
Shadow bytes around the buggy address:
  0x0c4a7fff83d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c4a7fff83e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c4a7fff83f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c4a7fff8400: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c4a7fff8410: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c4a7fff8420:[fa]fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c4a7fff8430: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c4a7fff8440: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c4a7fff8450: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c4a7fff8460: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c4a7fff8470: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==38438==ABORTING

POC

heap-overflow-slaxLexer-slaxlexer-1107.zip

printf fakes numbers, which fails for large values

I cheat with printf, and use xsltPopString() to pull values off the expression stack. This
is generally fine, but fails massively when the values are large numbers, where xslt prefers scientific notation.

% cat ~/trash/test.slax
version 1.2;

main {
slax:printf("%s", 12345123451234512345);
slax:printf("%d", 12345123451234512345);
}
% slaxproc -g -E ~/trash/test.slax

1.23451234512345e+19 1.23451234512345e+19

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.