Dear Paul and Thorsten,

I am not a Debian, but a Gentoo, user, but also found the same bug on
chktex-1.6.4. I have already filed a bug report in the gentoo tracker, as
well as the savannah project page:

https://bugs.gentoo.org/show_bug.cgi?id=383403
https://savannah.nongnu.org/bugs/?34322

I am copying here what I already reported there, but I thought you might be
interested to know the reason behing the bug.

The problem comes from line 221 of file FindErrs.c in the chktex-1.6.4
sources, where 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. In my case, when I upgraded glibc to
version 2.12.2, the bug actually occurred.

To fix the bug, 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 already submitted a patch file to both bug reports, so let's hope the bug
is fixed soon.

Cheers,

Edgar

Reply via email to