Skip to content

Commit

Permalink
Fix another segfault on unterminated verb (#82)
Browse files Browse the repository at this point in the history
Reconfigure Valgrind exit code so that we can differentiate Valgrind
failing due to finding a problem (exit code 15) and detex failing due to
input being considered incorrect (exit code 1).
  • Loading branch information
pkubowicz committed Dec 17, 2023
1 parent 75a1fa2 commit 57695d7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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.
8 changes: 1 addition & 7 deletions detex.l
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down
13 changes: 7 additions & 6 deletions test.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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 {
Expand All @@ -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;
}
}
Expand All @@ -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;
}
3 changes: 3 additions & 0 deletions test/unterminated-verb-nofinal.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\documentclass[draft]{book}
\begin{document}
\verb+abc

0 comments on commit 57695d7

Please sign in to comment.