From f170240ef735edc481f60e51527cbb5ee1acfd55 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Thu, 4 Jun 2015 17:39:55 +0200 Subject: [PATCH] gpg: Cleanup error code path in case of a bad trustdb. * g10/tdbio.c (tdbio_read_record): Fix returning of the error. -- Actually the returned error will anyway be GPG_ERR_TRUSTDB but the old code was not correct. Signed-off-by: Werner Koch --- g10/tdbio.c | 54 +++++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/g10/tdbio.c b/g10/tdbio.c index b6b5938e2..4c93c96c3 100644 --- a/g10/tdbio.c +++ b/g10/tdbio.c @@ -1487,34 +1487,36 @@ tdbio_read_record (ulong recnum, TRUSTREC *rec, int expected) { log_error (_("%s: not a trustdb file\n"), db_name ); err = gpg_error (GPG_ERR_TRUSTDB); - /* FIXME ^ */ } - p += 2; /* skip "gpg" */ - rec->r.ver.version = *p++; - rec->r.ver.marginals = *p++; - rec->r.ver.completes = *p++; - rec->r.ver.cert_depth = *p++; - rec->r.ver.trust_model = *p++; - rec->r.ver.min_cert_level = *p++; - p += 2; - rec->r.ver.created = buf32_to_ulong(p); p += 4; - rec->r.ver.nextcheck = buf32_to_ulong(p); p += 4; - p += 4; - p += 4; - rec->r.ver.firstfree =buf32_to_ulong(p); p += 4; - p += 4; - rec->r.ver.trusthashtbl =buf32_to_ulong(p); p += 4; - if (recnum) + else { - log_error( _("%s: version record with recnum %lu\n"), db_name, - (ulong)recnum ); - err = gpg_error (GPG_ERR_TRUSTDB); - } - else if (rec->r.ver.version != 3) - { - log_error( _("%s: invalid file version %d\n"), db_name, - rec->r.ver.version ); - err = gpg_error (GPG_ERR_TRUSTDB); + p += 2; /* skip "gpg" */ + rec->r.ver.version = *p++; + rec->r.ver.marginals = *p++; + rec->r.ver.completes = *p++; + rec->r.ver.cert_depth = *p++; + rec->r.ver.trust_model = *p++; + rec->r.ver.min_cert_level = *p++; + p += 2; + rec->r.ver.created = buf32_to_ulong(p); p += 4; + rec->r.ver.nextcheck = buf32_to_ulong(p); p += 4; + p += 4; + p += 4; + rec->r.ver.firstfree =buf32_to_ulong(p); p += 4; + p += 4; + rec->r.ver.trusthashtbl =buf32_to_ulong(p); p += 4; + if (recnum) + { + log_error( _("%s: version record with recnum %lu\n"), db_name, + (ulong)recnum ); + err = gpg_error (GPG_ERR_TRUSTDB); + } + else if (rec->r.ver.version != 3) + { + log_error( _("%s: invalid file version %d\n"), db_name, + rec->r.ver.version ); + err = gpg_error (GPG_ERR_TRUSTDB); + } } break;