]> git.ipfire.org Git - thirdparty/systemd.git/commit
string-util: beef up string_is_safe()
authorLennart Poettering <lennart@amutable.com>
Thu, 16 Apr 2026 07:03:24 +0000 (09:03 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 21 Apr 2026 15:07:53 +0000 (17:07 +0200)
commit812aa57d2cbcb037219552c48d4ec1a6754892aa
treee3fde4b5ca53a3e81f2b79ce38ae3937b04a3f0b
parenta84bbd15d964d02fd0f5d688865b39eeeae38d99
string-util: beef up string_is_safe()

This tightens the checks of string_is_safe() and then adds flags to
relax certain aspects of it.

This does alter the rules on certain strings we pass a bit. We mostly
tighten the rules (but I think it's find and good) but we relax them on
others.

I let claude review the changes in behaviour for the various call sites
that I made. It summarized things in this table:

  ╭───────────────────────────────────────────────────┬──────────────────────────────────────────────╮
  │ CALL SITE                                         │ EFFECTIVE DELTA                              │
  ├───────────────────────────────────────────────────┼──────────────────────────────────────────────┤
  │ src/basic/syslog-util  log_namespace_name_valid   │ +UTF-8 required (globs already blocked)      │
  │ src/bootctl  --efi-boot-option-description        │ RELAXED: '\' and quotes now permitted        │
  │ src/core/dbus-manager  pretimeout governor        │ +UTF-8, +no-globs                            │
  │ src/core/load-fragment  ExecStart= path           │ +UTF-8, +no-globs                            │
  │ src/core/main  pretimeout governor (kcmdline)     │ +UTF-8, +no-globs                            │
  │ src/core/service  sd_notify STATUS=               │ +no-globs (ASCII-only preserved)             │
  │ src/home/homectl  --<identity field>=             │ empty now REJECTED; +UTF-8                   │
  │ src/libsystemd-network  dhcp_option_parse_string  │ (equivalent, just explicit)                  │
  │ src/libsystemd-network  sd_dhcp_server boot_fname │ ""→NULL coerced; else equivalent             │
  │ src/libsystemd/journal  SYSLOG_IDENTIFIER fb      │ +UTF-8, +no-globs                            │
  │ src/libsystemd/sd-json  SD_JSON_STRICT strings    │ +UTF-8 required                              │
  │ src/login/logind  session desktop=                │ +UTF-8 required                              │
  │ src/pcrlock  EFI variable string                  │ +UTF-8                                       │
  │ src/pcrlock  EFI action string                    │ RELAXED: empty + '\' now ok; +UTF-8          │
  │ src/resolve  dns-delegate id (from filename)      │ +UTF-8, +no-globs                            │
  │ src/shared/boot-entry  boot_entry_token_valid     │ (equivalent)                                 │
  │ src/shared/conf-parser  section header            │ +UTF-8, +no-globs                            │
  │ src/shared/conf-parser  CONFIG_PARSE_STRING_SAFE  │ +UTF-8 required                              │
  │ src/shared/kbd-util  keymap_is_valid              │ (equivalent; folded into STRING_FILENAME)    │
  │ src/shared/tpm2  nvpcr name                       │ +UTF-8 required                              │
  │ src/shared/vconsole  x11 layout/model/variant/opt │ +UTF-8, +no-globs                            │
  │ src/systemctl  --kernel-cmdline=                  │ +0x7f DEL rejected; empty path split out     │
  │ src/veritysetup  salt=                            │ RELAXED: safety check removed entirely       │
  │ src/vmspawn  --ssh-key-type=                      │ +UTF-8 required                              │
  ╰───────────────────────────────────────────────────┴──────────────────────────────────────────────╯
26 files changed:
src/basic/string-util.c
src/basic/string-util.h
src/basic/syslog-util.c
src/bootctl/bootctl.c
src/core/dbus-manager.c
src/core/load-fragment.c
src/core/main.c
src/core/manager.c
src/core/service.c
src/home/homectl.c
src/libsystemd-network/dhcp-option.c
src/libsystemd-network/sd-dhcp-server.c
src/libsystemd/sd-journal/journal-send.c
src/libsystemd/sd-json/sd-json.c
src/login/logind-dbus.c
src/pcrlock/pcrlock.c
src/resolve/resolved-dns-delegate.c
src/shared/boot-entry.c
src/shared/conf-parser.c
src/shared/kbd-util.c
src/shared/tpm2-util.c
src/shared/vconsole-util.c
src/systemctl/systemctl.c
src/test/test-string-util.c
src/veritysetup/veritysetup.c
src/vmspawn/vmspawn.c