Skip to content

[BUG] Segfault when building CPU name without BIOS Vendor ID available #718

@matoro

Description

@matoro

General description of bug:

  • What happened: fastfetch crashes when trying to construct the CPU name, when it cannot find BIOS Vendor ID in the output of lscpu (which happens when run without root privileges).
  • What should happen: Should not crash.
  • Did it work in an older version: No
  • Where did you get the binary: Built from source
  • Does this issue still occurs in the latest dev build? Yes

Often helpful information:

Screenshot:

The content of the configuration file you use (if any): None

Output of fastfetch -c ci.jsonc --format json: This command segfaults without root privileges, output with root:

[
  {
    "type": "Title",
    "result": {
      "userName": "root",
      "hostName": "matoro-loongdev",
      "homeDir": "/root/",
      "exePath": "/usr/bin/fastfetch",
      "userShell": "/sbin/nologin",
      "pageSize": 16384
    },
    "stat": 0
  },
  {
    "type": "Separator",
    "error": "Unsupported for JSON format",
    "stat": 0
  },
  {
    "type": "OS",
    "result": {
      "buildID": "",
      "codename": "",
      "id": "gentoo",
      "idLike": "",
      "name": "Gentoo",
      "prettyName": "Gentoo Linux",
      "variant": "",
      "variantID": "",
      "version": "",
      "versionID": "2.14"
    },
    "stat": 0
  },
  {
    "type": "Host",
    "result": {
      "family": "",
      "name": "Loongson-3A5000-HV-7A2000-1w-V0.1-EVB",
      "version": "",
      "sku": "",
      "vendor": "Loongson",
      "serial": "",
      "uuid": ""
    },
    "stat": 0
  },
  {
    "type": "Bios",
    "result": {
      "date": "03/13/23 09:32:09",
      "release": "4.0",
      "vendor": "Loongson",
      "version": "Loongson-UDK2018-V4.0.05420-stable202302",
      "type": "UEFI"
    },
    "stat": 0
  },
  {
    "type": "Board",
    "result": {
      "name": "Loongson-LS3A5000-7A2000-1w-EVB-V1.21",
      "vendor": "Loongson",
      "version": "",
      "serial": ""
    },
    "stat": 0
  },
  {
    "type": "Chassis",
    "result": {
      "type": "Desktop",
      "vendor": "Loongson",
      "version": "",
      "serial": ""
    },
    "stat": 0
  },
  {
    "type": "Kernel",
    "result": {
      "architecture": "loongarch64",
      "name": "Linux",
      "release": "6.7.4-gentoo-loongarch64",
      "version": "#1 SMP PREEMPT Fri Feb  9 11:37:10 EST 2024",
      "displayVersion": ""
    },
    "stat": 0
  },
  {
    "type": "Uptime",
    "result": {
      "uptime": 268215950,
      "bootTime": 1708036230493
    },
    "stat": 0
  },
  {
    "type": "Processes",
    "result": 122,
    "stat": 0
  },
  {
    "type": "Packages",
    "result": {
      "all": 668,
      "apk": 0,
      "brew": 0,
      "brewCask": 0,
      "choco": 0,
      "dpkg": 0,
      "emerge": 668,
      "eopkg": 0,
      "flatpakSystem": 0,
      "flatpakUser": 0,
      "nixDefault": 0,
      "nixSystem": 0,
      "nixUser": 0,
      "pacman": 0,
      "paludis": 0,
      "pkg": 0,
      "pkgtool": 0,
      "macports": 0,
      "rpm": 0,
      "scoop": 0,
      "snap": 0,
      "winget": 0,
      "xbps": 0,
      "opkg": 0,
      "pacmanBranch": ""
    },
    "stat": 3
  },
  {
    "type": "Shell",
    "result": {
      "exe": "bash",
      "exeName": "bash",
      "exePath": "/bin/bash",
      "pid": 15709,
      "ppid": 15708,
      "processName": "bash",
      "prettyName": "bash",
      "version": "5.2.26",
      "tty": 0
    },
    "stat": 1
  },
  {
    "type": "Display",
    "error": "Couldn't detect display",
    "stat": 1
  },
  {
    "type": "Brightness",
    "error": "No result is detected.",
    "stat": 0
  },
  {
    "type": "Monitor",
    "error": "opendir(drmDirPath) == NULL",
    "stat": 0
  },
  {
    "type": "LM",
    "error": "Failed to get $XDG_SESSION_ID",
    "stat": 0
  },
  {
    "type": "DE",
    "error": "No DE found",
    "stat": 0
  },
  {
    "type": "WM",
    "error": "No WM found",
    "stat": 0
  },
  {
    "type": "WMTheme",
    "error": "WM Theme needs successful WM detection",
    "stat": 0
  },
  {
    "type": "Theme",
    "error": "No themes found",
    "stat": 0
  },
  {
    "type": "Icons",
    "error": "No icons could be found",
    "stat": 0
  },
  {
    "type": "Font",
    "error": "No fonts found",
    "stat": 0
  },
  {
    "type": "Cursor",
    "error": "Couldn't find cursor",
    "stat": 0
  },
  {
    "type": "Wallpaper",
    "error": "Failed to detect the current wallpaper path",
    "stat": 0
  },
  {
    "type": "Terminal",
    "result": {
      "processName": "tmux: server",
      "exe": "tmux",
      "exeName": "tmux",
      "exePath": "/usr/bin/tmux",
      "pid": 15708,
      "ppid": 1,
      "prettyName": "tmux",
      "version": ""
    },
    "stat": 0
  },
  {
    "type": "TerminalFont",
    "error": "Unknown terminal: tmux: server",
    "stat": 0
  },
  {
    "type": "TerminalSize",
    "result": {
      "columns": 85,
      "rows": 192,
      "width": 0,
      "height": 0
    },
    "stat": 101
  },
  {
    "type": "TerminalTheme",
    "error": "Failed to detect terminal theme",
    "stat": 100
  },
  {
    "type": "CPU",
    "result": {
      "cpu": "Loongson-3A5000-HV + Loongson-3A5000-HV Not Specified",
      "vendor": "Loongson",
      "cores": {
        "physical": 4,
        "logical": 4,
        "online": 4
      },
      "frequency": {
        "min": null,
        "max": null
      },
      "temperature": null
    },
    "stat": 3
  },
  {
    "type": "CPUUsage",
    "result": [
      0.0,
      0.0,
      0.0,
      0.0
    ],
    "stat": 200
  },
  {
    "type": "GPU",
    "result": [
      {
        "coreCount": null,
        "memory": {
          "dedicated": {
            "total": null,
            "used": null
          },
          "shared": {
            "total": null,
            "used": null
          }
        },
        "driver": "",
        "name": "Loongson Technology LLC Device 7A36 (VGA compatible)",
        "temperature": null,
        "type": "Unknown",
        "vendor": "Loongson Technology LLC",
        "platformApi": "",
        "frequency": null
      }
    ],
    "stat": 1
  },
  {
    "type": "Memory",
    "result": {
      "total": 8393474048,
      "used": 1689337856
    },
    "stat": 0
  },
  {
    "type": "Swap",
    "result": {
      "total": 0,
      "used": 0
    },
    "stat": 0
  },
  {
    "type": "Disk",
    "result": [
      {
        "bytes": {
          "available": 191885438976,
          "free": 204651536384,
          "total": 249849548800,
          "used": 45198012416
        },
        "files": {
          "total": 15564800,
          "used": 705189
        },
        "filesystem": "ext4",
        "mountpoint": "/",
        "mountFrom": "/dev/root",
        "name": "",
        "volumeType": [
          "Regular"
        ]
      },
      {
        "bytes": {
          "available": 1070395392,
          "free": 1070395392,
          "total": 1070579712,
          "used": 184320
        },
        "files": {
          "total": 0,
          "used": 0
        },
        "filesystem": "vfat",
        "mountpoint": "/boot/efi",
        "mountFrom": "/dev/nvme0n1p1",
        "name": "",
        "volumeType": [
          "Hidden"
        ]
      }
    ],
    "stat": 1
  },
  {
    "type": "Battery",
    "error": "opendir(\"/sys/class/power_supply/\") == NULL",
    "stat": 0
  },
  {
    "type": "PowerAdapter",
    "error": "opendir(\"/sys/class/power_supply/\") == NULL",
    "stat": 0
  },
  {
    "type": "Player",
    "error": "Fastfetch was compiled without DBus support",
    "stat": 0
  },
  {
    "type": "Media",
    "error": "Fastfetch was compiled without DBus support",
    "stat": 0
  },
  {
    "type": "LocalIp",
    "result": [
      {
        "defaultRoute": true,
        "ipv4": "192.168.5.10/24",
        "ipv6": "",
        "mac": "",
        "name": "enp5s0"
      }
    ],
    "stat": 0
  },
  {
    "type": "Wifi",
    "error": "No Wifi interfaces found",
    "stat": 0
  },
  {
    "type": "DateTime",
    "result": 1707768014954,
    "stat": 0
  },
  {
    "type": "Locale",
    "result": "en_US.UTF-8",
    "stat": 0
  },
  {
    "type": "Vulkan",
    "error": "fastfetch was compiled without vulkan support",
    "stat": 0
  },
  {
    "type": "OpenGL",
    "error": "Fastfetch was built without gl support.",
    "stat": 0
  },
  {
    "type": "OpenCL",
    "error": "Fastfetch was build without OpenCL support",
    "stat": 0
  },
  {
    "type": "Users",
    "result": [
      {
        "name": "matoro",
        "hostName": "",
        "sessionName": "pts/1",
        "clientIp": "",
        "loginTime": 1707768014540
      }
    ],
    "stat": 0
  },
  {
    "type": "Bluetooth",
    "error": "Fastfetch was compiled without DBus support",
    "stat": 0
  },
  {
    "type": "Sound",
    "error": "Fastfetch was built without libpulse support",
    "stat": 0
  },
  {
    "type": "Camera",
    "result": [],
    "stat": 0
  },
  {
    "type": "Gamepad",
    "error": "No devices detected",
    "stat": 0
  },
  {
    "type": "Weather",
    "error": "Failed to receive the server response",
    "stat": 1014
  },
  {
    "type": "NetIO",
    "result": [
      {
        "name": "enp5s0",
        "defaultRoute": true,
        "txBytes": 1384,
        "rxBytes": 1496,
        "txPackets": 14,
        "rxPackets": 11,
        "rxErrors": 0,
        "txErrors": 0,
        "rxDrops": 0,
        "txDrops": 0
      }
    ],
    "stat": 0
  },
  {
    "type": "DiskIO",
    "result": [
      {
        "name": "SAMSUNG MZVLB256HAHQ-000H1",
        "devPath": "/dev/nvme0n1",
        "bytesRead": 0,
        "bytesWritten": 0,
        "readCount": 0,
        "writeCount": 0
      }
    ],
    "stat": 0
  },
  {
    "type": "PhysicalDisk",
    "result": [
      {
        "name": "SAMSUNG MZVLB256HAHQ-000H1",
        "devPath": "/dev/nvme0n1",
        "interconnect": "NVMe",
        "kind": "SSD",
        "size": 256060514304,
        "serial": "S425NA0K985814",
        "removable": false,
        "readOnly": false,
        "revision": "EXD70H1Q",
        "temperature": null
      }
    ],
    "stat": 0
  },
  {
    "type": "Version",
    "result": {
      "projectName": "fastfetch",
      "architecture": "unknown",
      "version": "2.8.3",
      "versionTweak": "",
      "cmakeBuiltType": "RelWithDebInfo",
      "compileTime": "Feb 12 2024, 14:45:54",
      "compiler": "gcc 13.2.1",
      "debugMode": false,
      "libc": "glibc 2.38"
    },
    "stat": 0
  },
  {
    "type": "Break",
    "error": "Unsupported for JSON format",
    "stat": 0
  },
  {
    "type": "Colors",
    "error": "Unsupported for JSON format",
    "stat": 0
  }
]

Output of fastfetch --list-features:

threads
videodev2
System yyjson

If fastfatch crashed

Paste the stacktrace here. You may get it with:

$ gdb -q --args /usr/bin/fastfetch --multithreading false --structure CPU --pipe
Reading symbols from /usr/bin/fastfetch...
(gdb) r
Starting program: /usr/bin/fastfetch --multithreading false --structure CPU --pipe
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
[Detaching after fork from child process 7165]

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7df0f1c in strchrnul () from /lib64/libc.so.6
(gdb) bt full
#0  0x00007ffff7df0f1c in strchrnul () from /lib64/libc.so.6
No symbol table info available.
#1  0x00007ffff7df0ed8 in strchr () from /lib64/libc.so.6
No symbol table info available.
#2  0x00007ffff7df357c in strstr () from /lib64/libc.so.6
No symbol table info available.
#3  0x000055555567245c in ffDetectCPUImpl (options=0x55555571d9e0 <instance+1144>, cpu=0x7ffffffee9f8)
    at /usr/src/debug/app-misc/fastfetch-2.8.3/fastfetch-2.8.3/src/detection/cpu/cpu_linux.c:271
        pstart = 0x0
        buffer = {allocated = 1024, length = 639, 
          chars = 0x555555722100 "Architecture:        loongarch64\nCPU op-mode(s):      32-bit, 64-bit\nAddress sizes:       48 bits physical, 48 bits virtual\nByte Order:          Little Endian\nCPU(s):", ' ' <repeats 14 times>, "4\nOn-line CPU(s) lis"...}
        physicalCoresBuffer = {allocated = 0, length = 0, chars = 0x5555556da928 ""}
        cpuMHz = {allocated = 0, length = 0, chars = 0x5555556da928 ""}
        cpuIsa = {allocated = 0, length = 0, chars = 0x5555556da928 ""}
        cpuUarch = {allocated = 0, length = 0, chars = 0x5555556da928 ""}
        error = 0x0
#4  0x00005555555771b8 in ffDetectCPU (options=0x55555571d9e0 <instance+1144>, cpu=0x7ffffffee9f8) at /usr/src/debug/app-misc/fastfetch-2.8.3/fastfetch-2.8.3/src/detection/cpu/cpu.c:7
        error = 0xffffffffbac24e6a <error: Cannot access memory at address 0xffffffffbac24e6a>
        removeStrings = {0x0, 0x5555555553ad "memchr", 0x7ffff7fed640 "\230\325\376\367\377\177", 0xffffffff <error: Cannot access memory at address 0xffffffff>, 0x7ffff7d70e40 "\252n", 
          0x7ffff7fee940 "", 0x1 <error: Cannot access memory at address 0x1>, 0x7ffff7feef60 "\017WUUUU", 0x7ffffffeea80 "\206", 0x7ffffffee9e8 "x\374\330\367\377\177", 
          0x555555709668 "\354\211VUUU", 0x7ffffffeef80 "\236\362\376\377\377\177", 0x555555709668 "\354\211VUUU", 0x7ffff7ed5000 <main_arena+1744> "\360O\355\367\377\177", 
          0x5555556929a8 <main> "c\200\376\002a`\301)v@\301)v\200\301\002\214", 0x555555567ae0 "`\223\034", 0x55555571d360 <toupper@got[plt]> "x\374\330\367\377\177", 
          0x840 <error: Cannot access memory at address 0x840>}
#5  0x000055555559c660 in ffPrintCPU (options=0x55555571d9e0 <instance+1144>) at /usr/src/debug/app-misc/fastfetch-2.8.3/fastfetch-2.8.3/src/modules/cpu/cpu.c:19
        cpu = {name = {allocated = 0, length = 0, chars = 0x5555556da928 ""}, vendor = {allocated = 0, length = 0, chars = 0x5555556da928 ""}, coresPhysical = 4, coresLogical = 4, 
          coresOnline = 4, frequencyMin = nan(0x8000000000000), frequencyMax = nan(0x8000000000000), temperature = nan(0x8000000000000)}
        error = 0x7ffff7d70e40 "\252n"
#6  0x000055555556ccb8 in parseStructureCommand (line=0x5555557220d0 "CPU", customValues=0x7ffffffeeda8, fn=0x55555556c03c <genJsonResult>, jsonDoc=0x0)
    at /usr/src/debug/app-misc/fastfetch-2.8.3/fastfetch-2.8.3/src/common/commandoption.c:115
        baseInfo = 0x55555571d9e0 <instance+1144>
        modules = 0x55555571cc78 <C.lto_priv.0+32>
#7  0x000055555556cdc8 in ffPrintCommandOption (data=0x7ffffffeed98, jsonDoc=0x0) at /usr/src/debug/app-misc/fastfetch-2.8.3/fastfetch-2.8.3/src/common/commandoption.c:137
        colonIndex = 3
        ms = 0
        startIndex = 0
#8  0x00005555556922a4 in run (data=0x7ffffffeed98) at /usr/src/debug/app-misc/fastfetch-2.8.3/fastfetch-2.8.3/src/fastfetch.c:809
        useJsonConfig = false
#9  0x0000555555692a94 in main (argc=6, argv=0x7ffffffeef48) at /usr/src/debug/app-misc/fastfetch-2.8.3/fastfetch-2.8.3/src/fastfetch.c:870
        data = {structure = {allocated = 32, length = 3, chars = 0x5555557220d0 "CPU"}, customValues = {data = 0x0, elementSize = 40, length = 0, capacity = 0}, configLoaded = false}
(gdb) frame 3
#3  0x000055555567245c in ffDetectCPUImpl (options=0x55555571d9e0 <instance+1144>, cpu=0x7ffffffee9f8) at /usr/src/debug/app-misc/fastfetch-2.8.3/fastfetch-2.8.3/src/detection/cpu/cpu_linux.c:271
271                 while ((pstart = strstr(pstart, "Model name:")))
(gdb) l
266                                 return NULL;
267                         }
268                     }
269                 }
270
271                 while ((pstart = strstr(pstart, "Model name:")))
272                 {
273                     pstart += strlen("Model name:");
274                     while (isspace(*pstart)) ++pstart;
275                     if (*pstart == '\0')

The issue is due to the fact that the output of lscpu does not contain the BIOS Vendor ID field when run without root privileges. This means that fastfetch does not crash when run with root privileges, but it does crash when run without root.

Output of lscpu without root:

$ lscpu
Architecture:          loongarch64
  CPU op-mode(s):      32-bit, 64-bit
  Address sizes:       48 bits physical, 48 bits virtual
  Byte Order:          Little Endian
CPU(s):                4
  On-line CPU(s) list: 0-3
Model name:            Loongson-3A5000-HV
  CPU family:          Loongson-64bit
  Model:               0x11
  Thread(s) per core:  1
  Core(s) per socket:  4
  Socket(s):           1
  BogoMIPS:            5000.00
  Flags:               cpucfg lam ual fpu crc32 complex crypto lvz
Caches (sum of all):   
  L1d:                 256 KiB (4 instances)
  L1i:                 256 KiB (4 instances)
  L2:                  1 MiB (4 instances)
  L3:                  16 MiB (1 instance)

Output of lscpu with root:

$ sudo !!
sudo lscpu
Architecture:          loongarch64
  CPU op-mode(s):      32-bit, 64-bit
  Address sizes:       48 bits physical, 48 bits virtual
  Byte Order:          Little Endian
CPU(s):                4
  On-line CPU(s) list: 0-3
BIOS Vendor ID:        Loongson
Model name:            Loongson-3A5000-HV
  BIOS Model name:     Loongson-3A5000-HV Not Specified CPU @ 2.5GHz
  BIOS CPU family:     605
  CPU family:          Loongson-64bit
  Model:               0x11
  Thread(s) per core:  1
  Core(s) per socket:  4
  Socket(s):           1
  BogoMIPS:            5000.00
  Flags:               cpucfg lam ual fpu crc32 complex crypto lvz
Caches (sum of all):   
  L1d:                 256 KiB (4 instances)
  L1i:                 256 KiB (4 instances)
  L2:                  1 MiB (4 instances)
  L3:                  16 MiB (1 instance)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions