Bug 255765 - games/3dc: crashes, does not start
Summary: games/3dc: crashes, does not start
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: Fernando Apesteguía
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-05-11 00:48 UTC by Graham Perrin
Modified: 2021-05-13 13:00 UTC (History)
2 users (show)

See Also:
fernape: merge-quarterly+


Attachments
core (200.08 KB, application/gzip)
2021-05-11 00:48 UTC, Graham Perrin
no flags Details
Proposed patch (510 bytes, patch)
2021-05-12 08:45 UTC, Fernando Apesteguía
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Graham Perrin freebsd_committer freebsd_triage 2021-05-11 00:48:19 UTC
Created attachment 224826 [details]
core

% 3Dc
3Dc version 0.8.1, Copyright (C) 1995,1996 Paul Hicks
3Dc comes with ABSOLUTELY NO WARRANTY: see the GPL file for details
This is free software: you are welcome to redistribute it
    under certain conditions (see the GPL file).
Abort (core dumped)
% date ; uname -v
Tue 11 May 2021 01:46:51 BST
FreeBSD 14.0-CURRENT #94 main-n246499-097e8701c9f: Thu May  6 07:26:23 BST 2021     root@mowa219-gjp4-8570p:/usr/obj/usr/src/amd64.amd64/sys/GENERIC-NODEBUG 
%
Comment 1 Rainer Hurling freebsd_committer freebsd_triage 2021-05-11 16:04:15 UTC
After building games/3dc with debugging

#env WITH_DEBUG=yes STRIP=install portmaster -m 'DEBUG_FLAGS=-g' games/3dc

and than starting 3Dc in lldb gives me:

lldb /usr/local/bin/3Dc 
(lldb) target create "/usr/local/bin/3Dc"
Current executable set to '/usr/local/bin/3Dc' (x86_64).
(lldb) r
Process 290 launching
Process 290 launched: '/usr/local/bin/3Dc' (x86_64)
3Dc version 0.8.1, Copyright (C) 1995,1996 Paul Hicks
3Dc comes with ABSOLUTELY NO WARRANTY: see the GPL file for details
This is free software: you are welcome to redistribute it
    under certain conditions (see the GPL file).
Process 290 stopped
* thread #1, name = '3Dc', stop reason = signal SIGABRT
    frame #0: 0x00000008005f37aa libc.so.7`__sys_kill + 10
libc.so.7`__sys_kill:
->  0x8005f37aa <+10>: jb     0x8005f34c8
    0x8005f37b0 <+16>: retq   
    0x8005f37b1:       int3   
    0x8005f37b2:       int3   
(lldb) bt
* thread #1, name = '3Dc', stop reason = signal SIGABRT
  * frame #0: 0x00000008005f37aa libc.so.7`__sys_kill + 10
    frame #1: 0x00000008005f6a60 libc.so.7`___lldb_unnamed_symbol845$$libc.so.7 + 144
    frame #2: 0x00000008005f69d0 libc.so.7`__stack_chk_fail + 16
    frame #3: 0x000000000020d29b 3Dc`InitMainWindow(gfx=0x0000000000215c10) at xif.c:0
    frame #4: 0x000000000020ca26 3Dc`Init3DcGFX(argc=1, argv=0x00007fffffffd630) at xif.c:100:7
    frame #5: 0x00000000002065e4 3Dc`main(argc=1, argv=0x00007fffffffd630) at main.c:55:7
    frame #6: 0x0000000000206040 3Dc`_start + 256


From here on, someone with more knowledge will have to take over ;)

HTH,
Rainer
Comment 2 Fernando Apesteguía freebsd_committer freebsd_triage 2021-05-12 08:45:37 UTC
Created attachment 224864 [details]
Proposed patch

It is smashing the stack in one of the two XtVaGetValues calls.

Would you try the attached patch? It works for me in amd64.

I am no expert in the X11 API. I think the software is assuming sizeof(int) = 32 always and the XtVaGetValues is returning something bigger in the in/out bg parameter (64 bits)
Comment 3 Rainer Hurling freebsd_committer freebsd_triage 2021-05-12 09:16:38 UTC
Hi Fernando,

For me on 14.0-CURRENT amd64 your patch works like expected :)
Comment 4 commit-hook freebsd_committer freebsd_triage 2021-05-13 12:58:47 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=339d443d7b97dcef2ad415ff9cf743685ebea304

commit 339d443d7b97dcef2ad415ff9cf743685ebea304
Author:     Fernando Apesteguía <fernape@FreeBSD.org>
AuthorDate: 2021-05-12 09:01:40 +0000
Commit:     Fernando Apesteguía <fernape@FreeBSD.org>
CommitDate: 2021-05-13 12:51:00 +0000

    games/3dc: Fix crash on boot

    The call to XtVaGetValues returns a value that overwrites the `bc` variable and
    smashes the stack. Use a long instead.

    PR:     255765
    Reported by:    grahamperrin@gmail.com
    Tested by:      rhurling@
    MFH:            2021Q2

 games/3dc/Makefile                |  2 +-
 games/3dc/files/patch-xif.c (new) | 11 +++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)
Comment 5 commit-hook freebsd_committer freebsd_triage 2021-05-13 13:00:49 UTC
A commit in branch 2021Q2 references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=2c822c361c643b4ff4d741f6d4d293a54ab15eb3

commit 2c822c361c643b4ff4d741f6d4d293a54ab15eb3
Author:     Fernando Apesteguía <fernape@FreeBSD.org>
AuthorDate: 2021-05-12 09:01:40 +0000
Commit:     Fernando Apesteguía <fernape@FreeBSD.org>
CommitDate: 2021-05-13 12:56:13 +0000

    games/3dc: Fix crash on boot

    The call to XtVaGetValues returns a value that overwrites the `bc` variable and
    smashes the stack. Use a long instead.

    PR:     255765
    Reported by:    grahamperrin@gmail.com
    Tested by:      rhurling@
    MFH:            2021Q2

    (cherry picked from commit 339d443d7b97dcef2ad415ff9cf743685ebea304)

 games/3dc/Makefile                |  2 +-
 games/3dc/files/patch-xif.c (new) | 11 +++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)
Comment 6 Fernando Apesteguía freebsd_committer freebsd_triage 2021-05-13 13:00:54 UTC
Committed,

Thank you both!