mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-01 11:32:48 -05:00
Use strbuf to store results in prompts_t.
UBsan pointed out another memcpy from NULL (again with length 0) in the prompts_t system. When I looked at it, I realised that firstly prompt_ensure_result_size was an early not-so-good implementation of sgrowarray_nm that would benefit from being replaced with a call to the real one, and secondly, the whole system for storing prompt results should really have been replaced with strbufs with the no-move option, because that's doing all the same jobs better. So, now each prompt_t holds a strbuf in place of its previous manually managed string. prompt_ensure_result_size is gone (the console prompt-reading functions use strbuf_append, and everything else just adds to the strbuf in the usual marshal.c way). New functions exist to retrieve a prompt_t's result, either by reference or copied.
This commit is contained in:
11
cmdgen.c
11
cmdgen.c
@ -53,10 +53,10 @@ int console_get_userpass_input(prompts_t *p)
|
||||
int ret = 1;
|
||||
for (i = 0; i < p->n_prompts; i++) {
|
||||
if (promptsgot < nprompts) {
|
||||
p->prompts[i]->result = dupstr(prompts[promptsgot++]);
|
||||
prompt_set_result(p->prompts[i], prompts[promptsgot++]);
|
||||
if (cgtest_verbose)
|
||||
printf(" prompt \"%s\": response \"%s\"\n",
|
||||
p->prompts[i]->prompt, p->prompts[i]->result);
|
||||
p->prompts[i]->prompt, p->prompts[i]->result->s);
|
||||
} else {
|
||||
promptsgot++; /* track number of requests anyway */
|
||||
ret = 0;
|
||||
@ -777,7 +777,7 @@ int main(int argc, char **argv)
|
||||
perror("puttygen: unable to read passphrase");
|
||||
RETURN(1);
|
||||
} else {
|
||||
old_passphrase = dupstr(p->prompts[0]->result);
|
||||
old_passphrase = prompt_get_result(p->prompts[0]);
|
||||
free_prompts(p);
|
||||
}
|
||||
}
|
||||
@ -921,12 +921,13 @@ int main(int argc, char **argv)
|
||||
perror("puttygen: unable to read new passphrase");
|
||||
RETURN(1);
|
||||
} else {
|
||||
if (strcmp(p->prompts[0]->result, p->prompts[1]->result)) {
|
||||
if (strcmp(prompt_get_result_ref(p->prompts[0]),
|
||||
prompt_get_result_ref(p->prompts[1]))) {
|
||||
free_prompts(p);
|
||||
fprintf(stderr, "puttygen: passphrases do not match\n");
|
||||
RETURN(1);
|
||||
}
|
||||
new_passphrase = dupstr(p->prompts[0]->result);
|
||||
new_passphrase = prompt_get_result(p->prompts[0]);
|
||||
free_prompts(p);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user