GNU bug report logs - #70301
30.0.50; secrets-create-item mangles cyrillic passwords

Previous Next

Package: emacs;

Reported by: k.ninev <at> cdots.bg

Date: Tue, 9 Apr 2024 08:20:04 UTC

Severity: normal

Tags: patch

Found in version 30.0.50

Fixed in version 30.1

Done: Michael Albinus <michael.albinus <at> gmx.de>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Michael Albinus <michael.albinus <at> gmx.de>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 70301 <at> debbugs.gnu.org, k.ninev <at> cdots.bg
Subject: bug#70301: 30.0.50; secrets-create-item mangles cyrillic passwords
Date: Wed, 10 Apr 2024 17:32:43 +0200
[Message part 1 (text/plain, inline)]
Eli Zaretskii <eliz <at> gnu.org> writes:

Hi Eli,

> Does the patch below give good results?

Thanks for the patch. However, I believe we shouldn't fix it in
secrets.el, but in dbus.el.

> Michael, I think we have a similar problem in
> dbus-byte-array-to-string: when MULTIBYTE is non-nil, the function
> should call decode-coding-string on the unibyte string it produces
> instead of converting each byte to multibyte.  Because the bytes in
> the argument BYTE-ARRAY are not characters, they are raw bytes of the
> UTF-8 sequence, so calling 'string' on them is not TRT.

Yes. The following patch works for me. WDYT?

[Message part 2 (text/x-patch, inline)]
diff --git a/lisp/net/dbus.el b/lisp/net/dbus.el
index 46f85daba24..11c87e72d4e 100644
--- a/lisp/net/dbus.el
+++ b/lisp/net/dbus.el
@@ -997,17 +997,18 @@ dbus-string-to-byte-array
 STRING shall be UTF-8 coded."
   (if (zerop (length string))
       '(:array :signature "y")
-    (cons :array (mapcan (lambda (c) (list :byte c)) string))))
+    (cons :array
+          (mapcan (lambda (c) (list :byte c))
+                  (encode-coding-string string 'utf-8)))))

-(defun dbus-byte-array-to-string (byte-array &optional multibyte)
+(defun dbus-byte-array-to-string (byte-array &optional _multibyte)
   "Transform BYTE-ARRAY into UTF-8 coded string.
-BYTE-ARRAY must be a list of structure (c1 c2 ...), or a byte
-array as produced by `dbus-string-to-byte-array'.  The resulting
-string is unibyte encoded, unless MULTIBYTE is non-nil."
-  (apply
-   (if multibyte #'string #'unibyte-string)
-   (unless (equal byte-array '(:array :signature "y"))
-     (seq-filter #'characterp byte-array))))
+BYTE-ARRAY must be a unibyte list of structure (c1 c2 ...), or a byte
+array as produced by `dbus-string-to-byte-array'."
+   (if-let ((bytes (seq-filter #'characterp byte-array))
+            (string (apply #'unibyte-string bytes)))
+       (decode-coding-string string 'utf-8)
+     ""))

 (defun dbus-escape-as-identifier (string)
   "Escape an arbitrary STRING so it follows the rules for a C identifier.

This bug report was last modified 1 year and 95 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.