Skip to content

upsc segfaults (SIGSEGV) when querying remote upsd on FreeBSD 14.x with NUT 2.8.5 #3454

@Drinker09

Description

@Drinker09

Environment

Affected: NUT 2.8.5_1 on FreeBSD 14.3-RELEASE-p12 (OPNsense 26.1)
Working: NUT 2.8.2_1 on FreeBSD 15.0-RELEASE-p5
UPS Server: Raspberry Pi running NUT 2.8.1 in netserver mode (Raspberry Pi OS)
UPS: CyberPower CP1500PFCLCDa (usbhid-ups driver)

Describe the bug

When running upsc on FreeBSD 14.3 with NUT 2.8.5 to query a remote upsd server, the process terminates with a segmentation fault (SIGSEGV, exit code 11) after successfully connecting and receiving data — but before writing any output. This means no UPS data is returned to stdout regardless of whether output is redirected to a file, pipe, or captured by a calling process such as PHP shell_exec().
The same query against the same remote server works correctly on FreeBSD 15.0 with NUT 2.8.2, suggesting a regression introduced between NUT 2.8.2 and 2.8.5.

To Reproduce

On a FreeBSD 14.3 system with NUT 2.8.5 installed, query a remote NUT server:
upsc upsname@192.168.x.x
Expected result:
battery.charge: 100
battery.runtime: 11425
ups.status: OL
... (full variable list)
Actual result:
Segmentation fault
With output redirected to a file:
upsc upsname@192.168.x.x > /tmp/output.txt
Segmentation fault
The file is empty — no output is written before the crash.
Verified exit code is 11 (SIGSEGV) via PHP exec():
phpexec('/usr/local/bin/upsc upsname@192.168.x.x', $output, $return_code);
// $return_code = 11, $output = []

Additional context

The remote server itself is functioning correctly — other clients on the network can query it without issue. The NUT protocol socket connection works perfectly when implemented directly in PHP using fsockopen() on port 3493, retrieving full UPS data without any crash. This confirms the remote server is healthy and the bug is specific to the upsc binary when querying remote hosts.

This bug was discovered while attempting to use upsc from within the OPNsense NUT plugin's PHP diagnostics controller. The workaround implemented was to bypass upsc entirely and communicate with the remote upsd directly via TCP socket using the NUT protocol.

Workaround

Connect directly to upsd via TCP socket on port 3493 using the NUT protocol instead of calling upsc. Example in PHP:
php$socket = fsockopen('192.168.x.x', 3493, $errno, $errstr, 5);
fwrite($socket, "LIST VAR upsname\n");
// read response...

Metadata

Metadata

Assignees

No one assigned

    Labels

    FreeBSDissues related to FreeBSD and its derivatives (including pfSense)SSL/NSSIssues and PRs about SSL, TLS and other crypto-related mattersbugimpacts-release-2.8.5Issues reported against NUT release 2.8.5 (maybe vanilla or with minor packaging tweaks)

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions