bug-gnubg
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-gnubg] setting output digits to more than 4.


From: Øystein Schønning-Johansen
Subject: Re: [Bug-gnubg] setting output digits to more than 4.
Date: Sun, 3 May 2015 14:35:55 +0200

Hehe!
You are partly right, Lucas! I do indeed adjust the number of digits
on a Windows installation of GNU Backgammon and that does, as you say
work perfectly. However on Linux is crashes! I have backtracked the
crash and it comes from function OutputEquityScale in format.c.

format.c lines 468ff:

extern char *
OutputEquityScale(const float r, const cubeinfo * pci, const cubeinfo
* pciBase, const int f)
{

    static char sz[9];  /* <--- This buffer overflows! */

    if (!pci->nMatchTo) {
        if (f)
            sprintf(sz, "%+*.*f", fOutputDigits + 4, fOutputDigits,
pci->nCube / pciBase->nCube * r);
        else
            sprintf(sz, "%*.*f", fOutputDigits + 4, fOutputDigits,
pci->nCube / pciBase->nCube * r);
    } else {
..
.
.


So that's the problem. I guess the buffer is compiled bigger than the
9 bytes on Windows, and that it therefore works by luck. I guess the C
standards say that a such declaration should reserve at least N bytes.

Possible (naive) solution will be to increase the buffer size. Say set
it to 16 instead of 9.

Better solution: Rewrite the code such that the caller supplies the
buffer. I that way the function becomes re-entrant as well.

Best regards,
-Øystein


On Sun, May 3, 2015 at 10:33 AM, Lucas <address@hidden> wrote:
> I performed reveral rollouts with the digits set to 10
> and  my gnubg, also  1.05.000,   didn’t crash at all
>
> Lucas
>
> From: Øystein Schønning-Johansen
> Sent: Sunday, May 03, 2015 12:47 AM
> To: address@hidden
> Subject: [Bug-gnubg] setting output digits to more than 4.
>
> Hi,
>
> I just noticed a bug. When setting the number of outputs to 5 or more, the
> application crashes if I start a rollout. I think there is a buffer overflow
> somewhere.
>
> (No game) show version
> GNU Backgammon 1.05.000  Apr 25 2015
>
> Arch Linux from Arch/Community build!
>
> -Øystein
>
>
> ________________________________
> _______________________________________________
> Bug-gnubg mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/bug-gnubg
>
>
> _______________________________________________
> Bug-gnubg mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/bug-gnubg
>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]