]> granicus.if.org Git - strace/commitdiff
syscall.c: add sanity check for the target personality number
authorEugene Syromyatnikov <evgsyr@gmail.com>
Tue, 16 Jan 2018 16:38:35 +0000 (17:38 +0100)
committerDmitry V. Levin <ldv@altlinux.org>
Tue, 16 Jan 2018 22:54:38 +0000 (22:54 +0000)
We can never be cautious enough.

* defs.h (set_personality): Change argument type to unsigned int.
* syscall.c (set_personality): Change argument type to unsigned int,
check whether requested personality is sane, die otherwise.

defs.h
syscall.c

diff --git a/defs.h b/defs.h
index 2d9793e4cc3d87ceadec34a8a3d0564a35d7c251..7f8a10549cfd81c41ed3437d5e6c8353bed188d4 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -816,7 +816,7 @@ extern void tprintf_comment(const char *fmt, ...) ATTRIBUTE_FORMAT((printf, 1, 2
 extern void tprints_comment(const char *str);
 
 #if SUPPORTED_PERSONALITIES > 1
-extern void set_personality(int personality);
+extern void set_personality(unsigned int personality);
 extern unsigned current_personality;
 #else
 # define set_personality(personality) ((void)0)
index 67f6eaee83dabcd082b25d12f00de1f8832d1f9d..444bfa1ef25e6aa8b8a8a8553283cb5671514ebe 100644 (file)
--- a/syscall.c
+++ b/syscall.c
@@ -252,11 +252,15 @@ static const int personality_klongsize[SUPPORTED_PERSONALITIES] = {
 # endif
 
 void
-set_personality(int personality)
+set_personality(unsigned int personality)
 {
        if (personality == current_personality)
                return;
 
+       if (personality >= SUPPORTED_PERSONALITIES)
+               error_msg_and_die("Requested switch to unsupported personality "
+                                 "%u", personality);
+
        nsyscalls = nsyscall_vec[personality];
        sysent = sysent_vec[personality];