Menu

#20 Segmentation fault in acpi_listen

Next Release
accepted
bug (1)
2026-01-24
2026-01-23
No

While calling acpi_listen, if --time (-t)and --count (-c) flags called, it went to Segmentation fault (core dumped)

When I debug it I saw this:

(gdb) r
Starting program: /usr/bin/acpi_listen --time 1

Program received signal SIGSEGV, Segmentation fault.0x00005555554011d1 in handle_cmdline (argv=<synthetic pointer>, argc=<synthetic pointer>) at acpi_listen.c:173
173                if (!isdigit(optarg[0])) {
(gdb) bt
#0  0x00005555554011d1 in handle_cmdline (argv=<synthetic pointer>, argc=<synthetic pointer>) at acpi_listen.c:173
#1  main (argc=3, argv=0x7fffffffe398) at acpi_listen.c:69
(gdb) list 173
168                break;169            case 's':170                socketfile = optarg;171                break;172            case 't':173                if (!isdigit(optarg[0])) { <<<< 174                    usage(stderr);175                    exit(EXIT_FAILURE);176                }177                alarm(atoi(optarg));
(gdb) p optarg
$1 = 0x0
(gdb)

The issue basically isdigit function is taking parameter in wrong format. With switch case which option called then do some operations. As I can see here -c, -s, -t taking input and -v and -h is not taking input . When I run help function also I can verify from explanations of commands.

So I dig more and I found a struct

static struct option opts[] = {
    {"count", 0, 0, 'c'},
    {"socketfile", 1, 0, 's'},
    {"time", 0, 0, 't'},
    {"version", 0, 0, 'v'},
    {"help", 0, 0, 'h'},
    {NULL, 0, 0, 0},
};

I looked also definition of that struct

struct option
{
  const char name;
  int has_arg;
  int flag;
  int val;
};

As we can see clearly the second value should be 1, if it has argument. So we can say that since it is 0 in time and count it doesn’t take input and isdigit function taking NULL value and that’s why segmentation fault happens. To fix that basically we should change has_args value to 1.

I created a merge request with proposed fix https://sourceforge.net/p/acpid2/code/merge-requests/8/

Discussion

  • Ted Felix

    Ted Felix - 2026-01-24

    Merged as [0138f4]. Please test latest git.

     

    Related

    Commit: [0138f4]

  • Ted Felix

    Ted Felix - 2026-01-24
    • status: open --> accepted
     

Log in to post a comment.

MongoDB Logo MongoDB