diff --git a/ChangeLog b/ChangeLog index 322b18d..85f9b7b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -216,3 +216,5 @@ Include escaped percent sign in output (#70). Thanks to Max Leonhardt. Fixes to man page. Thanks to kberry and Hilmar Preusse. (Version 2.8.11) -- UNRELEASED + +Fixed segmentation fault on unterminated \verb. diff --git a/detex.l b/detex.l index 86a0138..591dc0a 100644 --- a/detex.l +++ b/detex.l @@ -360,15 +360,9 @@ VERBSYMBOL =|\\leq|\\geq|\\in|>|<|\\subseteq|\subseteq|\\subset|\\supset|\\sim|\ while ((c = input()) != verbchar && c != '\n' && c != EOF && c != 0) { putchar(c); } - if (verbchar == EOF || c == EOF) { + if (c != verbchar) { ErrorExit("\\verb not complete before eof"); } - if (c == '\n') { - char delim[2]; - delim[0] = verbchar; - delim[1] = 0; - Warning("\\verb not terminated before eol, delimiter", delim); - } } } diff --git a/test.pl b/test.pl index 163ac9c..4669f85 100755 --- a/test.pl +++ b/test.pl @@ -17,10 +17,11 @@ run_for_wrong_input("non-existent-file.tex"); run_for_wrong_input("non-existent-file.txt"); run_for_wrong_input("test/unterminated.tex"); -run_for_wrong_input("test/unterminated-verb-pipe.tex"); +run_for_input_with_error("test/unterminated-verb-pipe.tex"); run_for_input_with_error("test/unterminated-verb.tex"); run_for_input_with_error("test/unterminated-verb-eol.tex"); +run_for_input_with_error("test/unterminated-verb-nofinal.tex"); fuzz(); @@ -59,9 +60,9 @@ sub run_for_wrong_input { sub run_for_input_with_error { my ($input) = @_; print "Checking response for $input...\n"; + my $res = system(get_cmd("./delatex $input")); # https://www.perlmonks.org/?node_id=81640 - my $res = system(get_cmd("./delatex $input")) >> 8; - die "exit code $res" if ($res != 1); + die "exit code $res (" . ($res >> 8) . ")" if ($res != 1 << 8); } sub fuzz { @@ -72,9 +73,9 @@ sub fuzz { my $bytes = int(rand($sb->size)); printf("Fuzz: bytes %5d/%5d of %s. ", $bytes, $sb->size, $input); system("head -c $bytes $input > /tmp/trunc.tex"); - my $res = system(get_cmd("../delatex /tmp/trunc.tex > /tmp/trunc.log")) >> 8; + my $res = system(get_cmd("../delatex /tmp/trunc.tex > /tmp/trunc.log")); print "Exit code $res\n"; - if ($res != 0 && $res != 1) { + if ($res != 0 && $res != 1 << 8) { die; } } @@ -89,7 +90,7 @@ sub execute_cmd { sub get_cmd { my ($cmd) = @_; if ($ARGV[0] && $ARGV[0] eq '--valgrind') { - $cmd = "valgrind --leak-check=yes --leak-check=full --error-exitcode=1 $cmd"; + $cmd = "valgrind --leak-check=yes --leak-check=full --error-exitcode=15 $cmd"; } return $cmd; } diff --git a/test/unterminated-verb-nofinal.tex b/test/unterminated-verb-nofinal.tex new file mode 100644 index 0000000..6661c76 --- /dev/null +++ b/test/unterminated-verb-nofinal.tex @@ -0,0 +1,3 @@ +\documentclass[draft]{book} +\begin{document} +\verb+abc \ No newline at end of file