1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00

Add some missing casts in ctype functions.

I thought I'd found all of these before, but perhaps a few managed to
slip in since I last looked. The character argument to the <ctype.h>
functions must have the value of an unsigned char or EOF; passing an
ordinary char (unless you know char is unsigned on every platform the
code will ever go near) risks mistaking '\xFF' for EOF, and causing
outright undefined behaviour on byte values in the range 80-FE. Never
do it.

(cherry picked from commit a76109c586)
This commit is contained in:
Simon Tatham 2023-04-19 14:21:32 +01:00
parent 15081bb0ad
commit bece41ddb0
6 changed files with 14 additions and 11 deletions

View File

@ -425,7 +425,8 @@ bool sesschan_enable_x11_forwarding(
const unsigned char *hex = authdata_hex.ptr;
char hexbuf[3];
if (!isxdigit(hex[i]) || !isxdigit(hex[i+1])) {
if (!isxdigit((unsigned char)hex[i]) ||
!isxdigit((unsigned char)hex[i+1])) {
strbuf_free(authdata_bin);
return false; /* not hex */
}

View File

@ -63,7 +63,7 @@ bool validate_manual_hostkey(char *key)
if (r[3*i+2] != ':')
goto not_fingerprint; /* sorry */
for (i = 0; i < 16*3 - 1; i++)
key[i] = tolower(r[i]);
key[i] = tolower((unsigned char)r[i]);
key[16*3 - 1] = '\0';
return true;
}

View File

@ -1835,7 +1835,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
args = strchr(command, ' ');
if (args) {
*args++ = 0;
while(*args && isspace(*args)) args++;
while (*args && isspace((unsigned char)*args)) args++;
}
spawn_cmd(command, args, show);
}

View File

@ -1071,9 +1071,11 @@ static int check_compose_internal(int first, int second, int recurse)
if (recurse == 0) {
nc = check_compose_internal(second, first, 1);
if (nc == -1)
nc = check_compose_internal(toupper(first), toupper(second), 1);
nc = check_compose_internal(toupper((unsigned char)first),
toupper((unsigned char)second), 1);
if (nc == -1)
nc = check_compose_internal(toupper(second), toupper(first), 1);
nc = check_compose_internal(toupper((unsigned char)second),
toupper((unsigned char)first), 1);
}
return nc;
}
@ -1097,9 +1099,9 @@ int decode_codepage(const char *cp_name)
s = cp_name;
d = cpi->name;
for (;;) {
while (*s && !isalnum(*s) && *s != ':')
while (*s && !isalnum((unsigned char)*s) && *s != ':')
s++;
while (*d && !isalnum(*d) && *d != ':')
while (*d && !isalnum((unsigned char)*d) && *d != ':')
d++;
if (*s == 0) {
codepage = cpi->codepage;

View File

@ -173,7 +173,7 @@ void split_into_argv(char *cmdline, int *argc, char ***argv,
* First deal with the simplest of all special cases: if there
* aren't any arguments, return 0,NULL,NULL.
*/
while (*cmdline && isspace(*cmdline)) cmdline++;
while (*cmdline && isspace((unsigned char)*cmdline)) cmdline++;
if (!*cmdline) {
if (argc) *argc = 0;
if (argv) *argv = NULL;
@ -195,7 +195,7 @@ void split_into_argv(char *cmdline, int *argc, char ***argv,
bool quote;
/* Skip whitespace searching for start of argument. */
while (*p && isspace(*p)) p++;
while (*p && isspace((unsigned char)*p)) p++;
if (!*p) break;
/* We have an argument; start it. */
@ -206,7 +206,7 @@ void split_into_argv(char *cmdline, int *argc, char ***argv,
/* Copy data into the argument until it's finished. */
while (*p) {
if (!quote && isspace(*p))
if (!quote && isspace((unsigned char)*p))
break; /* argument is finished */
if (*p == '"' || *p == '\\') {

View File

@ -912,7 +912,7 @@ char *handle_restrict_acl_cmdline_prefix(char *p)
* pointer past the prefix. Returns the updated pointer (whether
* it moved or not).
*/
while (*p && isspace(*p))
while (*p && isspace((unsigned char)*p))
p++;
if (*p == '&' && p[1] == 'R' &&
(!p[2] || p[2] == '@' || p[2] == '&')) {