From 4c745dab4c6925fa17714c2214ed5941e5cbf64d Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Thu, 20 Feb 2025 20:24:28 +0100 Subject: Validate unmarshalled state + add man pages for (un)marshal functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- libterminput_unmarshal_keypress__.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'libterminput_unmarshal_keypress__.c') diff --git a/libterminput_unmarshal_keypress__.c b/libterminput_unmarshal_keypress__.c index 68a622d..f4b4fc6 100644 --- a/libterminput_unmarshal_keypress__.c +++ b/libterminput_unmarshal_keypress__.c @@ -3,13 +3,17 @@ int -libterminput_unmarshal_keypress__(struct libterminput_unmarshaller *how, struct libterminput_keypress *what) +libterminput_unmarshal_keypress__(struct libterminput_unmarshaller *how, struct libterminput_keypress *what) /* TODO test */ { what->type = LIBTERMINPUT_KEYPRESS; if (how->load(how, &what->key, sizeof(what->key)) || how->load(how, &what->times, sizeof(what->times)) || how->load(how, &what->mods, sizeof(what->mods))) return -1; + if ((uintmax_t)what->key > (uintmax_t)LIBTERMINPUT_KEYPAD__LAST__) { + errno = EINVAL; + return -1; + } if (what->key == LIBTERMINPUT_SYMBOL) { return how->load(how, what->symbol, sizeof(what->symbol)); } else { -- cgit v1.2.3-70-g09d2