mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-06 05:52: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:
@ -321,7 +321,6 @@ static int keycmp(void *av, void *bv)
|
||||
void provide_xrm_string(const char *string, const char *progname)
|
||||
{
|
||||
const char *p, *q;
|
||||
char *key;
|
||||
struct skeyval *xrms, *ret;
|
||||
|
||||
p = q = strchr(string, ':');
|
||||
@ -330,14 +329,13 @@ void provide_xrm_string(const char *string, const char *progname)
|
||||
" \"%s\"\n", progname, string);
|
||||
return;
|
||||
}
|
||||
q++;
|
||||
xrms = snew(struct skeyval);
|
||||
|
||||
while (p > string && p[-1] != '.' && p[-1] != '*')
|
||||
p--;
|
||||
xrms = snew(struct skeyval);
|
||||
key = snewn(q-p, char);
|
||||
memcpy(key, p, q-p);
|
||||
key[q-p-1] = '\0';
|
||||
xrms->key = key;
|
||||
xrms->key = mkstr(make_ptrlen(p, q-p));
|
||||
|
||||
q++;
|
||||
while (*q && isspace((unsigned char)*q))
|
||||
q++;
|
||||
xrms->value = dupstr(q);
|
||||
|
Reference in New Issue
Block a user