From a51406af124e712bc943b29c73fdf219e003ffaa Mon Sep 17 00:00:00 2001 From: sin Date: Wed, 15 Jul 2015 16:05:52 +0100 Subject: [PATCH] Fix confstr() check Do not crash unless the overflow would actually happen. --- include/unistd.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/unistd.h b/include/unistd.h index 5fa3b44..b8251ba 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -41,10 +41,11 @@ extern "C" { _FORTIFY_FN(confstr) size_t confstr(int __n, char *__s, size_t __l) { size_t __b = __builtin_object_size(__s, 0); + size_t __r = __orig_confstr(__n, __s, __b > __l ? __l : __b); - if (__l > __b) + if (__l > __b && __r > __b) __builtin_trap(); - return __orig_confstr(__n, __s, __l); + return __r; } _FORTIFY_FN(getcwd) char *getcwd(char *__s, size_t __l)