mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-15 01:57:40 -05:00
Rework handling of untrusted terminal data.
Now there's a centralised routine in misc.c to do the sanitisation, which copies data on to an outgoing bufchain. This allows me to remove from_backend_untrusted() completely from the frontend API, simplifying code in several places. Two use cases for untrusted-terminal-data sanitisation were in the terminal.c prompts handler, and in the collection of SSH-2 userauth banners. Both of those were writing output to a bufchain anyway, so it was very convenient to just replace a bufchain_add with sanitise_term_data and then not have to worry about it again. There was also a simplistic sanitiser in uxcons.c, which I've now replaced with a call to the good one - and in wincons.c there was a FIXME saying I ought to get round to that, which now I have!
This commit is contained in:
27
misc.c
27
misc.c
@ -826,6 +826,33 @@ int bufchain_try_fetch_consume(bufchain *ch, void *data, int len)
|
||||
}
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* Sanitise terminal output that we have reason not to trust, e.g.
|
||||
* because it appears in the login banner or password prompt from a
|
||||
* server, which we'd rather not permit to use arbitrary escape
|
||||
* sequences.
|
||||
*/
|
||||
|
||||
void sanitise_term_data(bufchain *out, const void *vdata, int len)
|
||||
{
|
||||
const char *data = (const char *)vdata;
|
||||
int i;
|
||||
|
||||
/*
|
||||
* FIXME: this method of sanitisation is ASCII-centric. It would
|
||||
* be nice to permit SSH banners and the like to contain printable
|
||||
* Unicode, but that would need a lot more complicated code here
|
||||
* (not to mention knowing what character set it should interpret
|
||||
* the data as).
|
||||
*/
|
||||
for (i = 0; i < len; i++) {
|
||||
if (data[i] == '\n')
|
||||
bufchain_add(out, "\r\n", 2);
|
||||
else if (data[i] >= ' ' && data[i] < 0x7F)
|
||||
bufchain_add(out, data + i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* My own versions of malloc, realloc and free. Because I want
|
||||
* malloc and realloc to bomb out and exit the program if they run
|
||||
|
Reference in New Issue
Block a user