1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-01 03:22:48 -05:00

Rewrite some manual char-buffer-handling code.

In the course of recent refactorings I noticed a couple of cases where
we were doing old-fashioned preallocation of a char array with some
conservative maximum size, then writing into it via *p++ or similar
and hoping we got the calculation right.

Now we have strbuf and dupcat, so we shouldn't ever have to do that.
Fixed as many cases as I could find by searching for allocations of
the form 'snewn(foo, char)'.

Particularly worth a mention was the Windows GSSAPI setup code, which
was directly using the Win32 Registry API, and looks much more legible
using the windows/utils/registry.c wrappers. (But that was why I had
to enhance them in the previous commit so as to be able to open
registry keys read-only: without that, the open operation would
actually fail on this key, which is not user-writable.)

Also unix/askpass.c, which was doing a careful reallocation of its
buffer to avoid secrets being left behind in the vacated memory -
which is now just a matter of ensuring we called strbuf_new_nm().
This commit is contained in:
Simon Tatham
2022-09-13 15:00:26 +01:00
parent 7339e00f4a
commit 6cf6682c54
13 changed files with 174 additions and 291 deletions

View File

@ -1588,19 +1588,17 @@ static void term_copy_stuff_from_conf(Terminal *term)
*/
{
char *answerback = conf_get_str(term->conf, CONF_answerback);
int maxlen = strlen(answerback);
term->answerback = snewn(maxlen, char);
term->answerbacklen = 0;
strbuf_clear(term->answerback);
while (*answerback) {
char *n;
char c = ctrlparse(answerback, &n);
if (n) {
term->answerback[term->answerbacklen++] = c;
put_byte(term->answerback, c);
answerback = n;
} else {
term->answerback[term->answerbacklen++] = *answerback++;
put_byte(term->answerback, *answerback++);
}
}
}
@ -1980,6 +1978,7 @@ Terminal *term_init(Conf *myconf, struct unicode_data *ucsdata, TermWin *win)
term->termstate = TOPLEVEL;
term->selstate = NO_SELECTION;
term->curstype = 0;
term->answerback = strbuf_new();
term_copy_stuff_from_conf(term);
@ -2095,7 +2094,7 @@ void term_free(Terminal *term)
sfree(term->ltemp);
sfree(term->wcFrom);
sfree(term->wcTo);
sfree(term->answerback);
strbuf_free(term->answerback);
for (i = 0; i < term->bidi_cache_size; i++) {
sfree(term->pre_bidi_cache[i].chars);
@ -3807,7 +3806,7 @@ static void term_out(Terminal *term, bool called_from_term_data)
if (term->ldisc) {
strbuf *buf = term_input_data_from_charset(
term, DEFAULT_CODEPAGE,
term->answerback, term->answerbacklen);
term->answerback->s, term->answerback->len);
ldisc_send(term->ldisc, buf->s, buf->len, false);
strbuf_free(buf);
}

View File

@ -300,8 +300,7 @@ struct terminal_tag {
* the former every time.
*/
bool ansi_colour;
char *answerback;
int answerbacklen;
strbuf *answerback;
bool no_arabicshaping;
int beep;
bool bellovl;