diff --git a/include/pcp.h b/include/pcp.h index 45255d0..b9881a9 100644 --- a/include/pcp.h +++ b/include/pcp.h @@ -8,7 +8,6 @@ extern "C" { #include "pcp/config.h" #include "pcp/base85.h" #include "pcp/buffer.h" -#include "pcp/config.h" #include "pcp/context.h" #include "pcp/crypto.h" #include "pcp/defines.h" diff --git a/libpcp/mgmt.c b/libpcp/mgmt.c index 794b2d2..664bf73 100644 --- a/libpcp/mgmt.c +++ b/libpcp/mgmt.c @@ -203,6 +203,7 @@ int _check_hash_keysig(PCPCTX *ptx, Buffer *blob, pcp_pubkey_t *p, pcp_keysig_t pcp_ks_bundle_t *pcp_import_binpub(PCPCTX *ptx, byte *raw, size_t rawsize) { Buffer *blob = buffer_new(512, "importblob"); + pcp_ks_bundle_t *bundle = NULL; buffer_add(blob, raw, rawsize); @@ -211,12 +212,16 @@ pcp_ks_bundle_t *pcp_import_binpub(PCPCTX *ptx, byte *raw, size_t rawsize) { if(version == PCP_KEY_VERSION) { /* ah, homerun */ - return pcp_import_pub_rfc(ptx, blob); + bundle = pcp_import_pub_rfc(ptx, blob); } else { /* nope, it's probably pbp */ - return pcp_import_pub_pbp(ptx, blob); + bundle = pcp_import_pub_pbp(ptx, blob); } + + buffer_free(blob); + return bundle; + } pcp_ks_bundle_t *pcp_import_pub(PCPCTX *ptx, byte *raw, size_t rawsize) { @@ -333,8 +338,7 @@ pcp_ks_bundle_t *pcp_import_pub_rfc(PCPCTX *ptx, Buffer *blob) { } pcp_ks_bundle_t *pcp_import_pub_pbp(PCPCTX *ptx, Buffer *blob) { - char *date = ucmalloc(19); - char *ignore = ucmalloc(46); + char *date = ucmalloc(20); char *parts = NULL; byte *sig = ucmalloc(crypto_sign_BYTES);; int pnum; @@ -363,8 +367,7 @@ pcp_ks_bundle_t *pcp_import_pub_pbp(PCPCTX *ptx, Buffer *blob) { goto errimp2; } - buffer_get_chunk(blob, ignore, 46); - free(ignore); + buffer_fwd_offset(blob, 46); memcpy(b->name, buffer_get(blob), buffer_left(blob)); /* parse the name */ @@ -791,7 +794,10 @@ pcp_key_t *pcp_import_secret(PCPCTX *ptx, byte *raw, size_t rawsize, char *passp } /* now we've got the blob, parse it */ - return pcp_import_secret_native(ptx, blob, passphrase); + pcp_key_t *sk = pcp_import_secret_native(ptx, blob, passphrase); + buffer_free(blob); + + return sk; } pcp_key_t *pcp_import_secret_native(PCPCTX *ptx, Buffer *cipher, char *passphrase) { @@ -857,7 +863,9 @@ pcp_key_t *pcp_import_secret_native(PCPCTX *ptx, Buffer *cipher, char *passphras buffer_free(blob); /* fill in the calculated fields */ - memcpy (sk->id, pcp_getkeyid(sk), 17); + char *id = pcp_getkeyid(sk); + memcpy (sk->id, id, 17); + free(id); sk->type = PCP_KEY_TYPE_SECRET; return sk; diff --git a/libpcp/z85.c b/libpcp/z85.c index 2eb08f4..f6b01dc 100644 --- a/libpcp/z85.c +++ b/libpcp/z85.c @@ -464,7 +464,7 @@ int z85_isbegin(Buffer *buf) { size_t blen; const char *begin; long int offset; - int i; + int i, isb; if(! z85_isheader(buf)) return 0; @@ -474,18 +474,21 @@ int z85_isbegin(Buffer *buf) { /* determine type */ len = buffer_left(buf); + isb = -1; byte *line = ucmalloc(len); /* FIXME: maybe wrong, check it */ buffer_get_chunk(buf, line, offset); + for(i=0; (begin=begins[i]); i++ ) { - if(begin == NULL) break; + if(begin == NULL) + break; blen = strlen(begin); if(blen <= len) if(_findoffset(line+buf->offset, len, (char *)begin, blen) >= 0) - return i; /* i = ENUM ZBEGINS */ + isb = i; /* i = ENUM ZBEGINS */ } - /* unknown but valid */ - return -1; + free(line); + return isb; } int z85_iscomment(Buffer *buf) {