1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-11-27 13:21:11 +03:00

Add more error checks to read_dsa_privatekey().

git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@562 7dcaeef0-15fb-0310-b436-a5af3365683c
This commit is contained in:
Andreas Schneider
2009-04-19 09:24:24 +00:00
parent e6474a34c3
commit a3c820cf94

View File

@@ -512,43 +512,62 @@ error:
static int read_dsa_privatekey(FILE *fp, gcry_sexp_t *r, ssh_auth_callback cb, static int read_dsa_privatekey(FILE *fp, gcry_sexp_t *r, ssh_auth_callback cb,
void *userdata, const char *desc) { void *userdata, const char *desc) {
STRING *p; BUFFER *buffer = NULL;
STRING *q; STRING *p = NULL;
STRING *g; STRING *q = NULL;
STRING *y; STRING *g = NULL;
STRING *x; STRING *y = NULL;
STRING *v; STRING *x = NULL;
BUFFER *buffer; STRING *v = NULL;
int rc = 1;
if (!(buffer=privatekey_file_to_buffer(fp, TYPE_DSS, cb, userdata, desc))) buffer = privatekey_file_to_buffer(fp, TYPE_DSS, cb, userdata, desc);
if (buffer == NULL) {
return 0; return 0;
if (!asn1_check_sequence(buffer)) }
{
if (!asn1_check_sequence(buffer)) {
buffer_free(buffer); buffer_free(buffer);
return 0; return 0;
} }
v=asn1_get_int(buffer);
if (ntohl(v->size)!=1 || v->string[0]!=0) v = asn1_get_int(buffer);
{ if (ntohl(v->size) != 1 || v->string[0] != 0) {
buffer_free(buffer); buffer_free(buffer);
return 0; return 0;
} }
p=asn1_get_int(buffer);
q=asn1_get_int(buffer); p = asn1_get_int(buffer);
g=asn1_get_int(buffer); q = asn1_get_int(buffer);
y=asn1_get_int(buffer); g = asn1_get_int(buffer);
x=asn1_get_int(buffer); y = asn1_get_int(buffer);
x = asn1_get_int(buffer);
buffer_free(buffer); buffer_free(buffer);
if (!p || !q || !g || !y || !x)
return 0; if (p == NULL || q == NULL || g == NULL || y == NULL || x == NULL) {
gcry_sexp_build(r,NULL,"(private-key(dsa(p %b)(q %b)(g %b)(y %b)(x %b)))",ntohl(p->size),p->string,ntohl(q->size),q->string,ntohl(g->size),g->string,ntohl(y->size),y->string,ntohl(x->size),x->string); rc = 0;
free(p); goto error;
free(q); }
free(g);
free(y); if (gcry_sexp_build(r, NULL,
free(x); "(private-key(dsa(p %b)(q %b)(g %b)(y %b)(x %b)))",
free(v); ntohl(p->size), p->string,
return 1; ntohl(q->size), q->string,
ntohl(g->size), g->string,
ntohl(y->size), y->string,
ntohl(x->size), x->string)) {
rc = 0;
}
error:
string_free(p);
string_free(q);
string_free(g);
string_free(y);
string_free(x);
string_free(v);
return rc;
} }
#endif /* HAVE_LIBGCRYPT */ #endif /* HAVE_LIBGCRYPT */