Skip to content

Handle upsmon NOTIFYCMD and upssched CMDSCRIPT values strictly as paths#3499

Merged
jimklimov merged 8 commits into
networkupstools:masterfrom
jimklimov:avoid-system
Jul 17, 2026
Merged

Handle upsmon NOTIFYCMD and upssched CMDSCRIPT values strictly as paths#3499
jimklimov merged 8 commits into
networkupstools:masterfrom
jimklimov:avoid-system

Conversation

@jimklimov

Copy link
Copy Markdown
Member

Documentation was vague about this, and implementation used system() which modern guidelines frown upon. Fix this to mean a single token with an exact path name (or a program in PATH) without arguments, inline scriptlets, etc.

NOTE: SHUTDOWNCMD should not be impacted by this change, and can still take arguments as is often does (e.g. shutdown -t now).

@jimklimov jimklimov added this to the 2.8.6 milestone Jun 22, 2026
@jimklimov jimklimov added upsmon Shutdowns and overrides and battery level triggers Issues and PRs about system shutdown, especially if battery charge/runtime remaining is involved Hardening Ideas and implems to make NUT deployments more robust and secure (relaxed convenience may suffer) labels Jun 22, 2026
@github-actions

github-actions Bot commented Jun 22, 2026

Copy link
Copy Markdown

A ZIP file with standard source tarball and another tarball with pre-built docs for commit 3f1da37 is temporarily available: NUT-tarballs-PR-3499.zip.

jimklimov added a commit to jimklimov/nut that referenced this pull request Jun 22, 2026
…CRIPT values strictly as paths [networkupstools#3499]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
@AppVeyorBot

Copy link
Copy Markdown

@AppVeyorBot

Copy link
Copy Markdown

@AppVeyorBot

Copy link
Copy Markdown

jimklimov added a commit to jimklimov/nut that referenced this pull request Jun 22, 2026
…CRIPT values strictly as paths [networkupstools#3499]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
@AppVeyorBot

Copy link
Copy Markdown

Build nut 2.8.5.4858-master completed (commit 56e169d096 by @jimklimov)

@AppVeyorBot

Copy link
Copy Markdown

…CRIPT values strictly as paths [networkupstools#3499]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
@AppVeyorBot

Copy link
Copy Markdown

Build nut 2.8.5.4896-master completed (commit 9d71ba391a by @jimklimov)

@AppVeyorBot

Copy link
Copy Markdown

Build nut 2.8.5.4898-master completed (commit 771863a5c8 by @jimklimov)

@jimklimov jimklimov changed the title upsmon, upssched: handle NOTIFYCMD and CMDSCRIPT values strictly as paths Handle upsmon NOTIFYCMD and upssched CMDSCRIPT values strictly as paths Jul 13, 2026
@jimklimov

Copy link
Copy Markdown
Member Author

UPDATE: Upon practical review, e.g. per examples in issue #3525 and PR #3527, there may be significant usage of multi-token command lines, such as the interpreter program name (cmd.exe or powershell.exe on Windows) separate from the script path name, and maybe some further parameters, e.g.:

CMDSCRIPT "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -NoProfile -ExecutionPolicy Bypass -File C:\\NUT\\cmd\\upssched-cmd.ps1"

NOTIFYCMD "C:\\NUT\\sbin\\upssched.exe -DDDDD"

# Not directly impacted by this PR as it gets no further args and safely goes still to `system()`
SHUTDOWNCMD "C:\\Windows\\System32\\shutdown.exe /s /t 0 /f"

This PR would break such use-cases, and should be extended to pass through multiple tokens seen by NUT "parseconf" code as separate argv[] entries to execve or CreateProcess calls, e.g.:

CMDSCRIPT "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe" "-NoProfile" "-ExecutionPolicy" "Bypass" "-File" "C:\\NUT\\cmd\\upssched-cmd.ps1"

NOTIFYCMD "C:\\NUT\\sbin\\upssched.exe" "-DDDDD"

# For good measure, still worth understanding this spelling (even if not requiring it)...
SHUTDOWNCMD "C:\\Windows\\System32\\shutdown.exe" "/s" "/t" "0" "/f"

…le command-line args as separately quoted tokens in the directive [networkupstools#3499]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
… in upsmon [networkupstools#3499]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…ert-related data [networkupstools#3499]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
jimklimov added a commit to jimklimov/nut that referenced this pull request Jul 15, 2026
…in one token [networkupstools#3499]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
jimklimov added a commit to jimklimov/nut that referenced this pull request Jul 15, 2026
Comment thread clients/upsmon.c Fixed
jimklimov added a commit to jimklimov/nut that referenced this pull request Jul 15, 2026
Comment thread clients/upsmon.c Dismissed
@AppVeyorBot

Copy link
Copy Markdown

Build nut 2.8.5.4927-master completed (commit f4a419731e by @jimklimov)

@AppVeyorBot

Copy link
Copy Markdown

Build nut 2.8.5.4930-master completed (commit 62ecd3005d by @jimklimov)

@AppVeyorBot

Copy link
Copy Markdown

Build nut 2.8.5.4931-master completed (commit 6a2b4569c3 by @jimklimov)

@jimklimov
jimklimov merged commit dffba91 into networkupstools:master Jul 17, 2026
22 of 25 checks passed
@jimklimov
jimklimov deleted the avoid-system branch July 17, 2026 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Hardening Ideas and implems to make NUT deployments more robust and secure (relaxed convenience may suffer) Shutdowns and overrides and battery level triggers Issues and PRs about system shutdown, especially if battery charge/runtime remaining is involved upsmon

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants