From f47690ecaa6a99e4650f75a61201b2138c5680f4 Mon Sep 17 00:00:00 2001 From: Andy Cedilnik Date: Tue, 5 Oct 2004 17:02:44 -0400 Subject: BUG: Prevent crash when strerror fails --- Source/CTest/Curl/strerror.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Source/CTest/Curl/strerror.c b/Source/CTest/Curl/strerror.c index 3179dd6..fafe9ec 100644 --- a/Source/CTest/Curl/strerror.c +++ b/Source/CTest/Curl/strerror.c @@ -539,11 +539,20 @@ const char *Curl_strerror(struct connectdata *conn, int err) /* this version of strerror_r() only *might* use the buffer we pass to the function, but it always returns the error message as a pointer, so we must copy that string unconditionally */ + if ( !msg ) + { + msg = "Unknown System Error"; + } strncpy(buf, msg, max); } #endif /* end of HAVE_GLIBC_STRERROR_R */ #else /* HAVE_STRERROR_R */ - strncpy(buf, strerror(err), max); + char *msg = strerror(err); + if ( !msg ) + { + msg = "Unknown System Error"; + } + strncpy(buf, msg, max); #endif /* end of HAVE_STRERROR_R */ #endif /* end of ! Windows */ -- cgit v0.12