From 5edcb9b308d84fdbb29b03e2940e3873fe28e4ed Mon Sep 17 00:00:00 2001 From: Gerhard Rieger Date: Fri, 8 Apr 2022 10:54:00 +0200 Subject: [PATCH] ctype(3) functions need there arguments to be unsigned char --- CHANGES | 3 +++ error.c | 2 +- sysutils.c | 6 +++--- utils.c | 2 +- vsnprintf_r.c | 2 +- xio-openssl.c | 2 +- xio-socket.c | 2 +- 7 files changed, 11 insertions(+), 8 deletions(-) diff --git a/CHANGES b/CHANGES index 0dceb3f..98be1c5 100644 --- a/CHANGES +++ b/CHANGES @@ -37,6 +37,9 @@ Corrections: or have trailing garbage. Test: INTEGER_GARBAGE + ctype(3) functions need there arguments to be unsigned char. + Thanks to Taylor R Campbell for sending a patch. + Porting: OpenSSL, at least 1.1 on Ubuntu, crashed with SIGSEGV under certain conditions: client connection to server with certificate with empty diff --git a/error.c b/error.c index f0ea73a..43ceebd 100644 --- a/error.c +++ b/error.c @@ -357,7 +357,7 @@ void msg2( syslp = bufp; *bufp++ = "DINWEF"[level]; #if 0 /* only for debugging socat */ - if (handler) bufp[-1] = tolower(bufp[-1]); /* for debugging, low chars indicate messages from signal handlers */ + if (handler) bufp[-1] = tolower((unsigned char)bufp[-1]); /* for debugging, low chars indicate messages from signal handlers */ #endif *bufp++ = ' '; strncpy(bufp, text, BUFLEN-(bufp-buff)-1); diff --git a/sysutils.c b/sysutils.c index 7f15128..32e4ba3 100644 --- a/sysutils.c +++ b/sysutils.c @@ -745,7 +745,7 @@ int xiosetenv(const char *varname, const char *value, int overwrite, const char progname = diag_get_string('p'); envname[0] = '\0'; strncat(envname, progname, XIO_ENVNAMELEN-1); l = strlen(envname); - for (i = 0; i < l; ++i) envname[i] = toupper(envname[i]); + for (i = 0; i < l; ++i) envname[i] = toupper((unsigned char)envname[i]); strncat(envname+l, "_", XIO_ENVNAMELEN-l-1); l += 1; strncat(envname+l, varname, XIO_ENVNAMELEN-l-1); @@ -771,7 +771,7 @@ int xiosetenv2(const char *varname, const char *varname2, const char *value, l += 1; strncat(envname+l, varname2, XIO_ENVNAMELEN-l-1); l += strlen(envname+l); - for (i = 0; i < l; ++i) envname[i] = toupper(envname[i]); + for (i = 0; i < l; ++i) envname[i] = toupper((unsigned char)envname[i]); return _xiosetenv(envname, value, overwrite, sep); # undef XIO_ENVNAMELEN } @@ -799,7 +799,7 @@ int xiosetenv3(const char *varname, const char *varname2, const char *varname3, l += 1; strncat(envname+l, varname3, XIO_ENVNAMELEN-l-1); l += strlen(envname+l); - for (i = 0; i < l; ++i) envname[i] = toupper(envname[i]); + for (i = 0; i < l; ++i) envname[i] = toupper((unsigned char)envname[i]); return _xiosetenv(envname, value, overwrite, sep); # undef XIO_ENVNAMELEN } diff --git a/utils.c b/utils.c index 63f8a6b..5760831 100644 --- a/utils.c +++ b/utils.c @@ -97,7 +97,7 @@ static size_t sanitize_char(char c, char *o, int style) { int hn; /* high nibble */ int ln; /* low nibble */ int n; /* written chars */ - if (isprint(c)) { + if (isprint((unsigned char)c)) { *o = c; return 1; } diff --git a/vsnprintf_r.c b/vsnprintf_r.c index fe8a966..3b691c8 100644 --- a/vsnprintf_r.c +++ b/vsnprintf_r.c @@ -404,7 +404,7 @@ int vsnprintf_r(char *str, size_t size, const char *format, va_list ap) { do { fsize = 10*fsize+(c-'0'); c = *format++; - } while (c && isdigit(c)); + } while (c && isdigit((unsigned char)c)); break; } if (c == '\0') { break; } diff --git a/xio-openssl.c b/xio-openssl.c index 48fffa2..7d088cf 100644 --- a/xio-openssl.c +++ b/xio-openssl.c @@ -1507,7 +1507,7 @@ static int openssl_delete_cert_info(void) { progname = diag_get_string('p'); envprefix[0] = '\0'; strncat(envprefix, progname, XIO_ENVNAMELEN-1); l = strlen(envprefix); - for (i = 0; i < l; ++i) envprefix[i] = toupper(envprefix[i]); + for (i = 0; i < l; ++i) envprefix[i] = toupper((unsigned char)envprefix[i]); strncat(envprefix+l, "_OPENSSL_", XIO_ENVNAMELEN-l-1); #if HAVE_VAR_ENVIRON diff --git a/xio-socket.c b/xio-socket.c index f02b3e2..465aaaf 100644 --- a/xio-socket.c +++ b/xio-socket.c @@ -1524,7 +1524,7 @@ int retropt_socket_pf(struct opt *opts, int *pf) { char *pfname; if (retropt_string(opts, OPT_PROTOCOL_FAMILY, &pfname) >= 0) { - if (isdigit(pfname[0])) { + if (isdigit((unsigned char)pfname[0])) { *pf = strtoul(pfname, NULL /*!*/, 0); #if WITH_IP4 } else if (!strcasecmp("inet", pfname) ||