summaryrefslogtreecommitdiff
path: root/src/filelock.c
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2022-04-25 10:46:28 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2022-04-25 14:09:53 +0200
commit9fdaf9ac4d0d26f93ffa4376ec26be9e33816f6a (patch)
tree8563821012c7aca45c009e98bf63b23bc0da057c /src/filelock.c
parentd932c402aa44c50af60085193b489bc1979cfbc3 (diff)
downloademacs-9fdaf9ac4d0d26f93ffa4376ec26be9e33816f6a.tar.gz
Protect against the host name containing an alpha character
* src/filelock.c (lock_file_1, current_lock_owner): Protect against the unlikely case that the host name contains an alpha character (bug#14250).
Diffstat (limited to 'src/filelock.c')
-rw-r--r--src/filelock.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/filelock.c b/src/filelock.c
index 67948e1f099..a657cc4582c 100644
--- a/src/filelock.c
+++ b/src/filelock.c
@@ -419,6 +419,13 @@ lock_file_1 (Lisp_Object lfname, bool force)
Lisp_Object luser_name = Fuser_login_name (Qnil);
Lisp_Object lhost_name = Fsystem_name ();
+ /* Protect against the extremely unlikely case of the host name
+ containing an @ character. */
+ if (!NILP (lhost_name) && strchr (SSDATA (lhost_name), '@'))
+ lhost_name = CALLN (Ffuncall, intern ("string-replace"),
+ build_string ("@"), build_string ("-"),
+ lhost_name);
+
char const *user_name = STRINGP (luser_name) ? SSDATA (luser_name) : "";
char const *host_name = STRINGP (lhost_name) ? SSDATA (lhost_name) : "";
char lock_info_str[MAX_LFINFO + 1];
@@ -583,6 +590,12 @@ current_lock_owner (lock_info_type *owner, Lisp_Object lfname)
.#test.txt -> larsi@.118961:1646577954) is an empty string. */
if (NILP (system_name))
system_name = build_string ("");
+ /* Protect against the extremely unlikely case of the host name
+ containing an @ character. */
+ else if (strchr (SSDATA (system_name), '@'))
+ system_name = CALLN (Ffuncall, intern ("string-replace"),
+ build_string ("@"), build_string ("-"),
+ system_name);
/* On current host? */
if (STRINGP (system_name)
&& dot - (at + 1) == SBYTES (system_name)