X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=sshpubk.c;h=cf9e44b365e1da223e4ac369e34a825ca45c3ae0;hb=cc66c86e7311c97db09da989c340ba3108c9e14f;hp=bd3c5e47c4cc66b5661844155e9e35acffa392ce;hpb=bbc9709b48515954f2f3eb631d1a6bea960bda18;p=PuTTY.git diff --git a/sshpubk.c b/sshpubk.c index bd3c5e47..cf9e44b3 100644 --- a/sshpubk.c +++ b/sshpubk.c @@ -67,14 +67,15 @@ static int loadrsakey_main(FILE * fp, struct RSAKey *key, int pub_only, i += 4; /* Now the serious stuff. An ordinary SSH-1 public key. */ - i += makekey(buf + i, len, key, NULL, 1); - if (i < 0) + j = makekey(buf + i, len, key, NULL, 1); + if (j < 0) goto end; /* overran */ + i += j; /* Next, the comment field. */ - j = GET_32BIT(buf + i); + j = toint(GET_32BIT(buf + i)); i += 4; - if (len - i < j) + if (j < 0 || len - i < j) goto end; comment = snewn(j + 1, char); if (comment) { @@ -462,7 +463,7 @@ static int read_header(FILE * fp, char *header) int len = 39; int c; - while (len > 0) { + while (1) { c = fgetc(fp); if (c == '\n' || c == '\r' || c == EOF) return 0; /* failure */ @@ -512,54 +513,6 @@ static char *read_body(FILE * fp) } } -int base64_decode_atom(char *atom, unsigned char *out) -{ - int vals[4]; - int i, v, len; - unsigned word; - char c; - - for (i = 0; i < 4; i++) { - c = atom[i]; - if (c >= 'A' && c <= 'Z') - v = c - 'A'; - else if (c >= 'a' && c <= 'z') - v = c - 'a' + 26; - else if (c >= '0' && c <= '9') - v = c - '0' + 52; - else if (c == '+') - v = 62; - else if (c == '/') - v = 63; - else if (c == '=') - v = -1; - else - return 0; /* invalid atom */ - vals[i] = v; - } - - if (vals[0] == -1 || vals[1] == -1) - return 0; - if (vals[2] == -1 && vals[3] != -1) - return 0; - - if (vals[3] != -1) - len = 3; - else if (vals[2] != -1) - len = 2; - else - len = 1; - - word = ((vals[0] << 18) | - (vals[1] << 12) | ((vals[2] & 0x3F) << 6) | (vals[3] & 0x3F)); - out[0] = (word >> 16) & 0xFF; - if (len > 1) - out[1] = (word >> 8) & 0xFF; - if (len > 2) - out[2] = word & 0xFF; - return len; -} - static unsigned char *read_blob(FILE * fp, int nlines, int *bloblen) { unsigned char *blob; @@ -1007,6 +960,8 @@ int ssh2_userkey_encrypted(const Filename *filename, char **commentptr) if (commentptr) *commentptr = comment; + else + sfree(comment); fclose(fp); if (!strcmp(b, "aes256-cbc"))