Commit ec393c03 authored by Brian Wellington's avatar Brian Wellington
Browse files

Error return cleanup.

parent 8c7fa43b
......@@ -19,7 +19,7 @@
/*
* Principal Author: Brian Wellington
* $Id: dst_parse.c,v 1.24 2000/09/02 01:15:22 bwelling Exp $
* $Id: dst_parse.c,v 1.25 2000/09/08 14:25:40 bwelling Exp $
*/
#include <config.h>
......@@ -189,18 +189,18 @@ dst__privstruct_parsefile(dst_key_t *key, const isc_uint16_t id,
const char *filename, isc_mem_t *mctx,
dst_private_t *priv)
{
int n = 0, ret, major, minor;
int n = 0, major, minor;
isc_buffer_t b;
isc_lex_t *lex = NULL;
isc_token_t token;
unsigned int opt = ISC_LEXOPT_EOL;
char *newfilename;
isc_result_t iret;
isc_result_t ret;
REQUIRE(priv != NULL);
if (strlen(filename) < 8)
return (DST_R_INVALIDPUBLICKEY);
return (DST_R_INVALIDPRIVATEKEY);
newfilename = isc_mem_get(mctx, strlen(filename) + 9);
if (newfilename == NULL)
......@@ -216,18 +216,18 @@ dst__privstruct_parsefile(dst_key_t *key, const isc_uint16_t id,
key->key_id = id;
iret = isc_lex_create(mctx, 1024, &lex);
if (iret != ISC_R_SUCCESS)
return (ISC_R_NOMEMORY);
ret = isc_lex_create(mctx, 1024, &lex);
if (ret != ISC_R_SUCCESS)
return (ret);
iret = isc_lex_openfile(lex, newfilename);
if (iret != ISC_R_SUCCESS)
ret = isc_lex_openfile(lex, newfilename);
if (ret != ISC_R_SUCCESS)
goto fail;
#define NEXTTOKEN(lex, opt, token) \
{ \
iret = isc_lex_gettoken(lex, opt, token); \
if (iret != ISC_R_SUCCESS) \
ret = isc_lex_gettoken(lex, opt, token); \
if (ret != ISC_R_SUCCESS) \
goto fail; \
}
......@@ -242,18 +242,30 @@ dst__privstruct_parsefile(dst_key_t *key, const isc_uint16_t id,
NEXTTOKEN(lex, opt, &token);
if (token.type != isc_tokentype_string ||
strcmp(token.value.as_pointer, PRIVATE_KEY_STR) != 0)
{
ret = DST_R_INVALIDPRIVATEKEY;
goto fail;
}
NEXTTOKEN(lex, opt, &token);
if (token.type != isc_tokentype_string ||
((char *)token.value.as_pointer)[0] != 'v')
{
ret = DST_R_INVALIDPRIVATEKEY;
goto fail;
}
if (sscanf(token.value.as_pointer, "v%d.%d", &major, &minor) != 2)
{
ret = DST_R_INVALIDPRIVATEKEY;
goto fail;
}
if (major > MAJOR_VERSION ||
(major == MAJOR_VERSION && minor > MINOR_VERSION))
{
ret = DST_R_INVALIDPRIVATEKEY;
goto fail;
}
READLINE(lex, opt, &token);
......@@ -263,12 +275,18 @@ dst__privstruct_parsefile(dst_key_t *key, const isc_uint16_t id,
NEXTTOKEN(lex, opt, &token);
if (token.type != isc_tokentype_string ||
strcmp(token.value.as_pointer, ALGORITHM_STR) != 0)
{
ret = DST_R_INVALIDPRIVATEKEY;
goto fail;
}
NEXTTOKEN(lex, opt | ISC_LEXOPT_NUMBER, &token);
if (token.type != isc_tokentype_number ||
token.value.as_ulong != (unsigned long) dst_key_alg(key))
{
ret = DST_R_INVALIDPRIVATEKEY;
goto fail;
}
READLINE(lex, opt, &token);
......@@ -280,13 +298,15 @@ dst__privstruct_parsefile(dst_key_t *key, const isc_uint16_t id,
unsigned char *data;
isc_region_t r;
iret = isc_lex_gettoken(lex, opt, &token);
if (iret == ISC_R_EOF)
ret = isc_lex_gettoken(lex, opt, &token);
if (ret == ISC_R_EOF)
break;
if (iret != ISC_R_SUCCESS)
if (ret != ISC_R_SUCCESS)
goto fail;
if (token.type != isc_tokentype_string)
if (token.type != isc_tokentype_string) {
ret = DST_R_INVALIDPRIVATEKEY;
goto fail;
}
memset(&priv->elements[n], 0, sizeof(dst_private_element_t));
tag = find_value(token.value.as_pointer, dst_key_alg(key));
......@@ -329,7 +349,7 @@ fail:
priv->nelements = n;
dst__privstruct_free(priv, mctx);
return (DST_R_INVALIDPRIVATEKEY);
return (ret);
}
int
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment