1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-10 09:58:01 +00:00

Fix translation of legacy registry RSA key format.

A user points out that in commit 6143a50ed2, when I converted all
use of the registry to functions that return a newly allocated buffer
instead of allocating a buffer themselves beforehand, I overlooked
that one use of the old idiom was reusing the preallocated buffer as
work space.

I _hope_ nobody still needs this code - the 'old-style' host key cache
format it handles was replaced in 2000. If anyone has a PuTTY host key
cache entry that's survived 22 years without either having to be
reinitialised on a new system or changed when the machine's host key
was upgraded, they're doing better than I am!

But if it's still here, it should still work, obviously. Replaced the
reused buffer with a strbuf, which is more robust anyway.
This commit is contained in:
Simon Tatham 2022-04-27 16:33:23 +01:00
parent de5f295b99
commit 93fb65af61

View File

@ -294,29 +294,26 @@ int check_stored_host_key(const char *hostname, int port,
* doesn't appear anyway in RSA keys) separated by a * doesn't appear anyway in RSA keys) separated by a
* comma. All hex digits are lowercase in both formats. * comma. All hex digits are lowercase in both formats.
*/ */
char *p = otherstr; strbuf *new = strbuf_new();
char *q = oldstyle; const char *q = oldstyle;
int i, j; int i, j;
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
int ndigits, nwords; int ndigits, nwords;
*p++ = '0'; put_datapl(new, PTRLEN_LITERAL("0x"));
*p++ = 'x';
ndigits = strcspn(q, "/"); /* find / or end of string */ ndigits = strcspn(q, "/"); /* find / or end of string */
nwords = ndigits / 4; nwords = ndigits / 4;
/* now trim ndigits to remove leading zeros */ /* now trim ndigits to remove leading zeros */
while (q[(ndigits - 1) ^ 3] == '0' && ndigits > 1) while (q[(ndigits - 1) ^ 3] == '0' && ndigits > 1)
ndigits--; ndigits--;
/* now move digits over to new string */ /* now move digits over to new string */
for (j = 0; j < ndigits; j++) for (j = ndigits; j-- > 0 ;)
p[ndigits - 1 - j] = q[j ^ 3]; put_byte(new, q[j ^ 3]);
p += ndigits;
q += nwords * 4; q += nwords * 4;
if (*q) { if (*q) {
q++; /* eat the slash */ q++; /* eat the slash */
*p++ = ','; /* add a comma */ put_byte(new, ','); /* add a comma */
} }
*p = '\0'; /* terminate the string */
} }
/* /*
@ -324,8 +321,9 @@ int check_stored_host_key(const char *hostname, int port,
* format. If not, we'll assume something odd went * format. If not, we'll assume something odd went
* wrong, and hyper-cautiously do nothing. * wrong, and hyper-cautiously do nothing.
*/ */
if (!strcmp(otherstr, key)) if (!strcmp(new->s, key))
put_reg_sz(rkey, regname->s, otherstr); put_reg_sz(rkey, regname->s, new->s);
strbuf_free(new);
} }
sfree(oldstyle); sfree(oldstyle);