Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 383403

Summary: chktex detects wrong file names when following \input commands
Product: Gentoo Linux Reporter: Edgar Gonzàlez i Pellicer <ausias.et.al>
Component: Current packagesAssignee: TeX project <tex>
Status: RESOLVED FIXED    
Severity: major    
Priority: Normal    
Version: unspecified   
Hardware: x86   
OS: Linux   
Whiteboard:
Package list:
Runtime testing required: ---
Attachments: Fix to the file FindErr.c, to replace an undefined call to strcpy
Fix to the file FindErr.c, to replace an undefined call to strcpy
Ebuild which includes the attached patch.
Fix to the file FindErr.c, to replace an undefined call to strcpy

Description Edgar Gonzàlez i Pellicer 2011-09-17 19:15:45 UTC
After upgrading glibc, I found that chktex was unable to follow the names of \input commands, because it misdetected the name between the {} delimiter pair. I tried to re-emerge chktex, but to no success.

Reproducible: Always

Steps to Reproduce:
Run chktex on a file which contains an \input command.


Actual Results:  
For the sample files main.tex:

\documentclass{article}
\input{part}

and part.tex:

\begin{document}
A \dots B
\end{document}

the output of:

$ chktex main.tex

is:

ChkTeX v1.6.4 - Copyright 1995-96 Jens T. Berger Thielemann.

chktex: WARNING -- Unable to open the TeX file `patt'.
Warning 27 in main.tex line 3: Could not execute LaTeX command.
\input{part}  
^^^^^^
No errors printed; One warning printed; No user suppressed warnings printed.


Expected Results:  
The output should be:

ChkTeX v1.6.4 - Copyright 1995-96 Jens T. Berger Thielemann.

Warning 1 in part.tex line 2: Command terminated with space.
A \dots B  
       ^
No errors printed; One warning printed; No user suppressed warnings printed.


On line 221 of file FindErrs.c in the chktex-1.6.4 sources, the following call is performed:

strcpy(OrigDest, OrigDest + 1);

According to the man page of strcpy(3), the src and dst strings should not overlap, so the results are undefined. When I emerged glibc to version 2.12.2, the bug actually occurred.

I have replaced the call for an alternative:

ShiftLeftOne(OrigDest);

defined as

static void ShiftLeftOne(char *Buf)
{
    char *P;

    for (P = Buf + 1; *P; ++P)
      *(P - 1) = *P;
    *(P - 1) = '\0';
}

I will now attach the patch file and the ebuild to fix it.
Comment 1 Edgar Gonzàlez i Pellicer 2011-09-17 19:16:58 UTC
Created attachment 286819 [details, diff]
Fix to the file FindErr.c, to replace an undefined call to strcpy

See bug report for a description of the detected bug, and my proposal to fix it.
Comment 2 Edgar Gonzàlez i Pellicer 2011-09-17 19:29:55 UTC
Created attachment 286821 [details, diff]
Fix to the file FindErr.c, to replace an undefined call to strcpy

My excuses! I attached the wrong patch format!
Comment 3 Edgar Gonzàlez i Pellicer 2011-09-17 19:32:08 UTC
Created attachment 286823 [details, diff]
Ebuild which includes the attached patch.

After

ebuild chktex-1.6.4-r1 merge

The compiled chktex no longer shows the bug.
Comment 4 Edgar Gonzàlez i Pellicer 2011-09-17 19:42:16 UTC
BTW, I also filed a bug report in the chktex project page:

https://savannah.nongnu.org/bugs/index.php?34322
Comment 5 Edgar Gonzàlez i Pellicer 2011-09-17 20:34:22 UTC
Created attachment 286825 [details, diff]
Fix to the file FindErr.c, to replace an undefined call to strcpy

The patched code I had previously attached could produce a segfault under certain conditions. This updated patch should fix it.
Comment 6 Alexis Ballier gentoo-dev 2015-04-29 15:10:05 UTC
should be fixed in 1.7.3 then