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

Remove a pointless allocation.

The char buffer 'blob' allocated in read_blob was never actually used
for anything, so there was no need to allocate it - and also no need
for the assert() just before it, which was added in commit
63a58759b5 to be extra safe against integer overflow when
computing the buffer size.

I feel a bit silly for having added that assertion in the first place
rather than removing the allocation it was protecting! It was
unnecessary even then, and I completely failed to notice :-)

(cherry picked from commit c780cffb7a)
This commit is contained in:
Simon Tatham 2022-09-13 15:48:11 +01:00
parent b8d40c7ae8
commit 7398dfa3fc

View File

@ -516,24 +516,18 @@ static char *read_body(BinarySource *src)
static bool read_blob(BinarySource *src, int nlines, BinarySink *bs) static bool read_blob(BinarySource *src, int nlines, BinarySink *bs)
{ {
unsigned char *blob;
char *line; char *line;
int linelen; int linelen;
int i, j, k; int i, j, k;
/* We expect at most 64 base64 characters, ie 48 real bytes, per line. */ /* We expect at most 64 base64 characters, ie 48 real bytes, per line. */
assert(nlines < MAX_KEY_BLOB_LINES);
blob = snewn(48 * nlines, unsigned char);
for (i = 0; i < nlines; i++) { for (i = 0; i < nlines; i++) {
line = read_body(src); line = read_body(src);
if (!line) { if (!line)
sfree(blob);
return false; return false;
}
linelen = strlen(line); linelen = strlen(line);
if (linelen % 4 != 0 || linelen > 64) { if (linelen % 4 != 0 || linelen > 64) {
sfree(blob);
sfree(line); sfree(line);
return false; return false;
} }
@ -542,14 +536,12 @@ static bool read_blob(BinarySource *src, int nlines, BinarySink *bs)
k = base64_decode_atom(line + j, decoded); k = base64_decode_atom(line + j, decoded);
if (!k) { if (!k) {
sfree(line); sfree(line);
sfree(blob);
return false; return false;
} }
put_data(bs, decoded, k); put_data(bs, decoded, k);
} }
sfree(line); sfree(line);
} }
sfree(blob);
return true; return true;
} }