From 0b085cbcf1e50288a3146011f754e853f0ac3851 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Thu, 25 Sep 2014 15:30:27 +0200 Subject: [PATCH] Fix strerror_r(3) range error case. --- libc/string/strerror_r.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libc/string/strerror_r.cpp b/libc/string/strerror_r.cpp index 08b992ca..743b3b2b 100644 --- a/libc/string/strerror_r.cpp +++ b/libc/string/strerror_r.cpp @@ -1,6 +1,6 @@ /******************************************************************************* - Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013. + Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013, 2014. This file is part of the Sortix C Library. @@ -30,7 +30,8 @@ extern "C" int strerror_r(int errnum, char* dest, size_t dest_len) const char* msg = sortix_strerror(errnum); if ( !msg ) return -1; - if ( strlcpy(dest, msg, dest_len) != strlen(msg) ) - errno = ERANGE; + if ( dest_len < strlen(msg) + 1 ) + return errno = ERANGE; + strcpy(dest, msg); return 0; }