triggerhappy icon indicating copy to clipboard operation
triggerhappy copied to clipboard

Segmentation Fault in th-cmd on Raspberry Pi 4

Open pproenca opened this issue 2 years ago • 3 comments

I ran into a issue recently with th-cmd on my raspberry pi and hope this is the right place to report it.

tl;dr Segmentation Fault in th-cmd on Raspberry Pi When Running with --socket /var/run/thd.socket --passfd --udev Options

Details

When running th-cmd with the --socket /var/run/thd.socket --passfd --udev options, the program crashes with a segmentation fault.

System Information:

  • Raspberry Pi Model: 4B+ 8GB
  • Operating System: RaspiOS 64-bit
  • th-cmd version: 0.5.0
  • glibc version: 2.31 (Debian GLIBC 2.31-13+rpt2+rpi1+deb11u5)

Steps to Reproduce:

  1. Run th-cmd with the command /usr/sbin/th-cmd --socket /var/run/thd.socket --passfd --udev.
  2. Observe segmentation fault.

Expected Results:

The th-cmd should run without any issues.

Actual Results:

Segmentation fault occurs, and the following is observed when debugging with gdb:

Program received signal SIGSEGV, Segmentation fault.
0x0000007ff7e10740 in __GI___strcasecmp (s1=0x5555551c58 "add", s2=0x0) at strcasecmp.c:58
58	strcasecmp.c: No such file or directory.

Additional Information:

Logs from systemd-udevd indicate:

Aug 21 18:00:00 pioshost systemd-udevd[203]: event0: Process '/usr/sbin/th-cmd --socket /var/run/thd.socket --passfd --udev' failed with exit code 1.
Aug 21 18:00:00 pioshost systemd-udevd[210]: event1: Process '/usr/sbin/th-cmd --socket /var/run/thd.socket --passfd --udev' failed with exit code 1.

Debugging Attempts:

  1. Checked system and application logs using journalctl -xe and dmesg. No additional relevant information found.
  2. Reinstalled glibc but the issue persists.

pproenca avatar Aug 27 '23 17:08 pproenca

Also seeing exact same issue on RPi4 with 4GB

stuart-bee-ops avatar Jan 09 '24 19:01 stuart-bee-ops

Issue seems to be null string into strcasecmp. Don't know how triggerhappy works, but looks like ACTION and DEVNAME are to be passed through environmental variables, aren't defined, and segfaults. It might be that original strcasecmp was OK with a null string, but retropie version isn't.

You can define some bogus environmental variables, e.g., "export DEVNAME=bogus; ACTION=bogus" or patch th-cmd. I've hacked th-cmd.c locally to avoid the segfault, but I'm not certain it's the root of my problems (trying to get wiimote to connect to pi 4 board).


diff --git a/th-cmd.c b/th-cmd.c
index aa2ba34..c40c05f 100644
--- a/th-cmd.c
+++ b/th-cmd.c
@@ -107,6 +107,10 @@ int main(int argc, char *argv[]) {

        int err = 0;
        if (op_udev) {
+         if( getenv("ACTION") == 0 ||
+             getenv("DEVNAME") == 0 ){
+           fprintf(stderr, "ACTION and/or DEVNAME not defined: ACTION=%s DEVNAME=%s\n", getenv("ACTION"), getenv("DEVNAME"));
+         } else {
                if (strcasecmp("add", getenv("ACTION")) == 0) {
                        ctype = CMD_ADD;
                } else if (strcasecmp("remove", getenv("ACTION")) == 0) {
@@ -116,6 +120,7 @@ int main(int argc, char *argv[]) {
                if ( ctype && dev ) {
                        err = send_command( s, ctype, dev, passfd, grab_dev, tag );
                }
+         }
        } else {
                /* get devices from command line */
                if (op_add) ctype = CMD_ADD;

This might have to do with a udev rule recommended to change the permissions

KERNEL=="uinput", MODE="0666"

There's no defined ACTION here.

marmarjohnson avatar Mar 03 '24 16:03 marmarjohnson

Seeing this same issue on a pizero-w. I can get the command to run manually by prefixing with those env variables, but it still crashes when invoked by the udev subsystem even after I hacked the rules to define those variables

jkp avatar Mar 27 '24 21:03 jkp