Page MenuHomeFreeBSD

D57562.id179685.diff
No OneTemporary

D57562.id179685.diff

diff --git a/sbin/md5/md5.1 b/sbin/md5/md5.1
--- a/sbin/md5/md5.1
+++ b/sbin/md5/md5.1
@@ -1,4 +1,4 @@
-.Dd April 6, 2026
+.Dd June 13, 2026
.Dt MD5 1
.Os
.Sh NAME
@@ -91,6 +91,10 @@
using the
.Dv VIS_CSTYLE \&| Dv VIS_OCTAL
style.
+Whether a character is printable is determined by the
+.Ev LC_CTYPE
+locale category, so in a UTF-8 or other multibyte locale valid
+multibyte characters are passed through unencoded.
.Pp
It is conjectured that it is computationally infeasible to
produce two messages having the same message digest, or to produce any
diff --git a/sbin/md5/md5.c b/sbin/md5/md5.c
--- a/sbin/md5/md5.c
+++ b/sbin/md5/md5.c
@@ -26,6 +26,7 @@
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
+#include <locale.h>
#include <md5.h>
#include <osreldate.h>
#include <ripemd.h>
@@ -430,6 +431,8 @@
size_t len;
struct chksumrec *rec;
+ setlocale(LC_CTYPE, "");
+
if ((progname = strrchr(argv[0], '/')) == NULL)
progname = argv[0];
else
diff --git a/sbin/md5/tests/md5_test.sh b/sbin/md5/tests/md5_test.sh
--- a/sbin/md5/tests/md5_test.sh
+++ b/sbin/md5/tests/md5_test.sh
@@ -390,6 +390,39 @@
atf_check sha1sum --quiet --check digests
}
+atf_test_case filename_encoding
+filename_encoding_head()
+{
+ atf_set descr "Verify locale-aware encoding of filenames (PR 295875)"
+ atf_set require.progs "md5"
+}
+filename_encoding_body()
+{
+ locale -a 2>/dev/null | grep -Fqx 'C.UTF-8' ||
+ atf_skip "C.UTF-8 locale not available"
+
+ # к о п и я .doc, the UTF-8 name from PR 295875.
+ name='копия.doc'
+ digest=b1946ac92492d2347c6235b4d2611184
+ printf 'hello\n' >"$name"
+
+ # In a UTF-8 locale a valid multibyte name passes through verbatim.
+ printf '%s %s\n' "$digest" "$name" >expected.utf8
+ atf_check -o file:expected.utf8 env LC_ALL=C.UTF-8 md5 -r "$name"
+
+ # In the C locale the high bytes are still octal-escaped.
+ printf '%s %s\n' "$digest" \
+ '\320\272\320\276\320\277\320\270\321\217.doc' >expected.c
+ atf_check -o file:expected.c env LC_ALL=C md5 -r "$name"
+
+ # Control characters are escaped even in a UTF-8 locale.
+ ctrl="$(printf 'a\tb')"
+ : >"$ctrl"
+ printf '%s %s\n' d41d8cd98f00b204e9800998ecf8427e 'a\tb' \
+ >expected.ctrl
+ atf_check -o file:expected.ctrl env LC_ALL=C.UTF-8 md5 -r "$ctrl"
+}
+
atf_init_test_cases()
{
for alg in $algorithms ; do
@@ -406,4 +439,5 @@
atf_add_test_case gnu_bflag
atf_add_test_case gnu_cflag
atf_add_test_case gnu_cflag_mode
+ atf_add_test_case filename_encoding
}

File Metadata

Mime Type
text/plain
Expires
Mon, Jul 13, 10:49 PM (11 h, 25 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
35047811
Default Alt Text
D57562.id179685.diff (2 KB)

Event Timeline