[Bug 296987] bin/md5 (md5sum/sha256sum/...): filenames with UTF-8 characters are always octal-escaped regardless of locale (missing setlocale())
[email protected] Thu, 23 Jul 2026 01:53:35 +0000
| Newsgroups | gmane.os.freebsd.bugs |
|---|---|
| Message-ID | <[email protected]/bugzilla/> |
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=296987
Bug ID: 296987
Summary: bin/md5 (md5sum/sha256sum/...): filenames with UTF-8
characters are always octal-escaped regardless of
locale (missing setlocale())
Product: Base System
Version: 15.1-RELEASE
Hardware: Any
OS: Any
Status: New
Severity: Affects Many People
Priority: ---
Component: bin
Assignee: [email protected]
Reporter: [email protected]
## Summary
md5sum, sha256sum, and the other GNU-compatible *sum links always
byte-escape non-ASCII filename bytes (via strnvis(), VIS_CSTYLE |
VIS_OCTAL) even when the process locale is a UTF-8 locale, because
sbin/md5/md5.c never calls setlocale(). strnvis() therefore always
operates in the default "C" locale, treating every UTF-8 continuation
byte as non-printable.
## Reproduction
$ locale
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
...
$ echo abc > testÄÖÜ.txt
$ md5sum testÄÖÜ.txt
<hash> test\303\204\303\226\303\234.txt
Expected: filename printed as-is (UTF-8), matching the active locale,
consistent with GNU coreutils' own behavior for a UTF-8 locale.
## Root cause
sbin/md5/md5.c, function safename() (uses strnvis() with VIS_CSTYLE |
VIS_OCTAL) — the file never calls setlocale(). Confirmed via source
inspection of releng/15.1 (commit 0f691888dc56).
## Suggested fix
Add setlocale(LC_CTYPE, ""); (with #include <locale.h>) early in
main(), before any strnvis() call.
## Environment
FreeBSD 15.1-RELEASE-p1, arm64
This did not occur on FreeBSD 14.3, where sbin/md5/md5.c had no
vis()-based filename escaping at all (feature added alongside the
GNU-sum-compatible output modes in 15.x).
--
You are receiving this mail because:
You are the assignee for the bug.