Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mRemoteNG/PuTTYNG.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2020-01-21 23:19:47 +0300
committerSimon Tatham <anakin@pobox.com>2020-01-21 23:39:04 +0300
commitcd6bc14f04382127a6617e10a82beb0232675d70 (patch)
tree5661e545c58c7a4f157af409b9382eb406ccf9e3 /cmdgen.c
parent5891142aee5cab4aedd4a6be32e80fba806f3326 (diff)
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.
Diffstat (limited to 'cmdgen.c')
-rw-r--r--cmdgen.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/cmdgen.c b/cmdgen.c
index e7242f49..286c12e9 100644
--- a/cmdgen.c
+++ b/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);
}
}