summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2020-06-27 10:20:00 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2020-06-27 10:20:00 +0000
commitb7203e62c114ede00b610f090be7f837b00da1f7 (patch)
tree4736c7392ec6abe062c4f1194eb3d53a6fa8d508 /usr.bin
parent528ac0f9c7ab06aab4efd9e38b0fb2eec3822cbf (diff)
Fix 0x Unicode character parsing, GitHub issue 2286.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/tmux/key-string.c32
1 files changed, 23 insertions, 9 deletions
diff --git a/usr.bin/tmux/key-string.c b/usr.bin/tmux/key-string.c
index 83bbcb24376..58581d43f3c 100644
--- a/usr.bin/tmux/key-string.c
+++ b/usr.bin/tmux/key-string.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: key-string.c,v 1.61 2020/05/25 18:57:25 nicm Exp $ */
+/* $OpenBSD: key-string.c,v 1.62 2020/06/27 10:19:59 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -18,7 +18,9 @@
#include <sys/types.h>
+#include <stdlib.h>
#include <string.h>
+#include <wchar.h>
#include "tmux.h"
@@ -163,13 +165,13 @@ key_code
key_string_lookup_string(const char *string)
{
static const char *other = "!#()+,-.0123456789:;<=>'\r\t";
- key_code key;
- u_int u;
- key_code modifiers;
- struct utf8_data ud;
- u_int i;
+ key_code key, modifiers;
+ u_int u, i;
+ struct utf8_data ud, *udp;
enum utf8_state more;
utf8_char uc;
+ char m[MB_LEN_MAX + 1];
+ int mlen;
/* Is this no key or any key? */
if (strcasecmp(string, "None") == 0)
@@ -181,9 +183,21 @@ key_string_lookup_string(const char *string)
if (string[0] == '0' && string[1] == 'x') {
if (sscanf(string + 2, "%x", &u) != 1)
return (KEYC_UNKNOWN);
- if (u > 0x1fffff)
- return (KEYC_UNKNOWN);
- return (u);
+ mlen = wctomb(m, u);
+ if (mlen <= 0 || mlen > MB_LEN_MAX)
+ return (KEYC_UNKNOWN);
+ m[mlen] = '\0';
+
+ udp = utf8_fromcstr(m);
+ if (udp == NULL ||
+ udp[0].size == 0 ||
+ udp[1].size != 0 ||
+ utf8_from_data(&udp[0], &uc) != UTF8_DONE) {
+ free(udp);
+ return (KEYC_UNKNOWN);
+ }
+ free(udp);
+ return (uc);
}
/* Check for modifiers. */