diff --git a/src/misc/pem/pem_pkcs.c b/src/misc/pem/pem_pkcs.c index 252f49be..ebf0b44e 100644 --- a/src/misc/pem/pem_pkcs.c +++ b/src/misc/pem/pem_pkcs.c @@ -213,9 +213,10 @@ int pem_decode_pkcs_filehandle(FILE *f, ltc_pka_key *k, const password_ctx *pw_c int pem_decode_pkcs(const void *buf, unsigned long len, ltc_pka_key *k, const password_ctx *pw_ctx) { - LTC_ARGCHK(buf != NULL); - LTC_ARGCHK(len != 0); + LTC_ARGCHK(buf != NULL || len == 0); LTC_ARGCHK(k != NULL); + if (len == 0) + return CRYPT_OK; { struct get_char g = pem_get_char_init(buf, len); return s_decode(&g, k, pw_ctx); diff --git a/src/misc/pem/pem_ssh.c b/src/misc/pem/pem_ssh.c index 89dfeb4e..bf4008db 100644 --- a/src/misc/pem/pem_ssh.c +++ b/src/misc/pem/pem_ssh.c @@ -541,11 +541,15 @@ static int s_parse_line(char *line, unsigned long *len, ltc_pka_key *key, char * static int s_read_authorized_keys(const void *buf, unsigned long len, ssh_authorized_key_cb cb, void *ctx) { char *s; - int err; + int err = CRYPT_OK; unsigned long clen = len; - ltc_pka_key *key = XCALLOC(1, sizeof(*key)); + ltc_pka_key *key = NULL; char *comment = NULL; - void *cpy = XMALLOC(len); + void *cpy = NULL; + if (clen == 0) + return CRYPT_OK; + key = XCALLOC(1, sizeof(*key)); + cpy = XMALLOC(len); if (key == NULL || cpy == NULL) { if (cpy) XFREE(cpy); @@ -835,9 +839,10 @@ int ssh_read_authorized_keys_filehandle(FILE *f, ssh_authorized_key_cb cb, void int pem_decode_openssh(const void *buf, unsigned long len, ltc_pka_key *k, const password_ctx *pw_ctx) { - LTC_ARGCHK(buf != NULL); - LTC_ARGCHK(len != 0); + LTC_ARGCHK(buf != NULL || len == 0); LTC_ARGCHK(k != NULL); + if (len == 0) + return CRYPT_OK; { struct get_char g = pem_get_char_init(buf, len); return s_decode_openssh(&g, k, pw_ctx); @@ -846,9 +851,10 @@ int pem_decode_openssh(const void *buf, unsigned long len, ltc_pka_key *k, const int ssh_read_authorized_keys(const void *buf, unsigned long len, ssh_authorized_key_cb cb, void *ctx) { - LTC_ARGCHK(buf != NULL); - LTC_ARGCHK(len != 0); + LTC_ARGCHK(buf != NULL || len == 0); LTC_ARGCHK(cb != NULL); + if (len == 0) + return CRYPT_OK; return s_read_authorized_keys(buf, len, cb, ctx); }