]> the.earth.li Git - onak.git/commitdiff
Fix issues found by llvm scan-build static analysis
authorJonathan McDowell <noodles@earth.li>
Sat, 9 Nov 2013 16:34:08 +0000 (08:34 -0800)
committerJonathan McDowell <noodles@earth.li>
Sat, 9 Nov 2013 16:34:08 +0000 (08:34 -0800)
A mixture of fixes: some variables set but never used (fix by either
removing or correctly checking error codes), some unlikely but possible
memory leaks, some invalid casting.

13 files changed:
decodekey.c
getcgi.c
keyd.c
keydb.c
keydb_db4.c
keydb_fs.c
keydb_hkp.c
keydb_keyd.c
keydctl.c
maxpath.c
onak.c
parsekey.c
sixdegrees.c

index b4f7ceb46781d45f376385c4cea0ac42affffb63..aeb7c623c516a959a277bf0b7177792fb5e472b8 100644 (file)
@@ -61,11 +61,11 @@ int parse_subpackets(unsigned char *data, uint64_t *keyid, time_t *creation)
                } else if (packetlen == 255) {
                        packetlen = data[offset++];
                        packetlen <<= 8;
-                       packetlen = data[offset++];
+                       packetlen |= data[offset++];
                        packetlen <<= 8;
-                       packetlen = data[offset++];
+                       packetlen |= data[offset++];
                        packetlen <<= 8;
-                       packetlen = data[offset++];
+                       packetlen |= data[offset++];
                }
                switch (data[offset] & 0x7F) {
                case OPENPGP_SIGSUB_CREATION:
index 203584149b1e38320b397916a7ea161aae7d6162..b36ad9b3e2f2d39688c18c06079ecab19f9e1ad7 100644 (file)
--- a/getcgi.c
+++ b/getcgi.c
@@ -200,14 +200,14 @@ char **getcgivars(int argc, char *argv[])
        for(i=0; cgiinput[i]; i++) if (cgiinput[i]=='+') cgiinput[i] = ' ';
 
        /* First, split on "&" to extract the name-value pairs into pairlist */
-       pairlist=(char **) malloc(256*sizeof(char **));
+       pairlist= malloc(256*sizeof(char *));
        paircount=0;
        nvpair=strtok(cgiinput, "&");
        while (nvpair) {
                pairlist[paircount++]= strdup(nvpair) ;
                if (!(paircount%256)) {
-                       pairlist=(char **) realloc(pairlist,
-                                       (paircount+256)*sizeof(char **));
+                       pairlist= realloc(pairlist,
+                                       (paircount+256)*sizeof(char *));
                }
                nvpair=strtok(NULL, "&") ;
        }
@@ -216,7 +216,7 @@ char **getcgivars(int argc, char *argv[])
 
        /* Then, from the list of pairs, extract the names and values */
        
-       cgivars=(char **) malloc((paircount*2+1)*sizeof(char **));
+       cgivars= malloc((paircount*2+1)*sizeof(char *));
        
        for (i=0; i<paircount; i++) {
                if ((eqpos=strchr(pairlist[i], '='))!=NULL) {
diff --git a/keyd.c b/keyd.c
index f3966db96dcdbafde6b92b341566b1199da791a7..5cd7b57564968e68680b3562103959638c025ef1 100644 (file)
--- a/keyd.c
+++ b/keyd.c
@@ -65,7 +65,7 @@ void daemonize(void)
                exit(EXIT_SUCCESS);
        }
 
-       pid = setsid();
+       setsid();
 
        freopen("/dev/null", "r", stdin);
        freopen("/dev/null", "w", stdout);
@@ -139,8 +139,12 @@ int sock_init(const char *sockname)
 
        if (ret != -1) {
                ret = listen(fd, 5);
+               if (ret == -1) {
+                       close(fd);
+                       fd = -1;
+               }
        }
-       
+
        return fd;
 }
 
@@ -535,6 +539,9 @@ int main(int argc, char *argv[])
        while ((optchar = getopt(argc, argv, "c:fh")) != -1 ) {
                switch (optchar) {
                case 'c':
+                       if (configfile != NULL) {
+                               free(configfile);
+                       }
                        configfile = strdup(optarg);
                        break;
                case 'f':
diff --git a/keydb.c b/keydb.c
index 14418fb7a012e86b2de55f494dd941b3654e609e..57472f9da64356035865d2ee1654e5bb7e7e4e76 100644 (file)
--- a/keydb.c
+++ b/keydb.c
@@ -241,7 +241,6 @@ int generic_update_keys(struct onak_dbctx *dbctx,
                        newkeys++;
                }
                dbctx->endtrans(dbctx);
-               intrans = false;
        }
 
        if (sendsync && keys != NULL) {
index 9d5dd9009fcf85f2e4e27e04983e598260b11b5c..6a21fab73678a811a286eeff35a6d3d7e97f2351 100644 (file)
@@ -176,16 +176,18 @@ static int db4_upgradedb(struct onak_db4_dbctx *privctx)
 
        logthing(LOGTHING_NOTICE, "Upgrading DB4 database");
        ret = db_env_create(&privctx->dbenv, 0);
-       privctx->dbenv->set_errcall(privctx->dbenv, &db4_errfunc);
-       privctx->dbenv->remove(privctx->dbenv, config.db_dir, 0);
-       privctx->dbenv = NULL;
+       if (ret == 0) {
+               privctx->dbenv->set_errcall(privctx->dbenv, &db4_errfunc);
+               privctx->dbenv->remove(privctx->dbenv, config.db_dir, 0);
+               privctx->dbenv = NULL;
+       }
        for (i = 0; i < privctx->numdbs; i++) {
                ret = db_create(&curdb, NULL, 0);
                if (ret == 0) {
                        snprintf(buf, sizeof(buf) - 1, "%s/keydb.%d.db",
                                config.db_dir, i);
                        logthing(LOGTHING_DEBUG, "Upgrading %s", buf);
-                       ret = curdb->upgrade(curdb, buf, 0);
+                       curdb->upgrade(curdb, buf, 0);
                        curdb->close(curdb, 0);
                } else {
                        logthing(LOGTHING_ERROR, "Error upgrading DB %s : %s",
@@ -198,7 +200,7 @@ static int db4_upgradedb(struct onak_db4_dbctx *privctx)
        if (ret == 0) {
                snprintf(buf, sizeof(buf) - 1, "%s/worddb", config.db_dir);
                logthing(LOGTHING_DEBUG, "Upgrading %s", buf);
-               ret = curdb->upgrade(curdb, buf, 0);
+               curdb->upgrade(curdb, buf, 0);
                curdb->close(curdb, 0);
        } else {
                logthing(LOGTHING_ERROR, "Error upgrading DB %s : %s",
@@ -210,7 +212,7 @@ static int db4_upgradedb(struct onak_db4_dbctx *privctx)
        if (ret == 0) {
                snprintf(buf, sizeof(buf) - 1, "%s/id32db", config.db_dir);
                logthing(LOGTHING_DEBUG, "Upgrading %s", buf);
-               ret = curdb->upgrade(curdb, buf, 0);
+               curdb->upgrade(curdb, buf, 0);
                curdb->close(curdb, 0);
        } else {
                logthing(LOGTHING_ERROR, "Error upgrading DB %s : %s",
@@ -222,7 +224,7 @@ static int db4_upgradedb(struct onak_db4_dbctx *privctx)
        if (ret == 0) {
                snprintf(buf, sizeof(buf) - 1, "%s/skshashdb", config.db_dir);
                logthing(LOGTHING_DEBUG, "Upgrading %s", buf);
-               ret = curdb->upgrade(curdb, buf, 0);
+               curdb->upgrade(curdb, buf, 0);
                curdb->close(curdb, 0);
        } else {
                logthing(LOGTHING_ERROR, "Error upgrading DB %s : %s",
@@ -234,7 +236,7 @@ static int db4_upgradedb(struct onak_db4_dbctx *privctx)
        if (ret == 0) {
                snprintf(buf, sizeof(buf) - 1, "%s/subkeydb", config.db_dir);
                logthing(LOGTHING_DEBUG, "Upgrading %s", buf);
-               ret = curdb->upgrade(curdb, buf, 0);
+               curdb->upgrade(curdb, buf, 0);
                curdb->close(curdb, 0);
        } else {
                logthing(LOGTHING_ERROR, "Error upgrading DB %s : %s",
@@ -270,6 +272,10 @@ static uint64_t db4_getfullkeyid(struct onak_dbctx *dbctx, uint64_t keyid)
                                &cursor,
                                0);   /* flags */
 
+               if (ret != 0) {
+                       return 0;
+               }
+
                shortkeyid = keyid & 0xFFFFFFFF;
 
                memset(&key, 0, sizeof(key));
@@ -292,7 +298,7 @@ static uint64_t db4_getfullkeyid(struct onak_dbctx *dbctx, uint64_t keyid)
                        }
                }
 
-               ret = cursor->c_close(cursor);
+               cursor->c_close(cursor);
                cursor = NULL;
        }
 
@@ -444,6 +450,11 @@ static int db4_fetch_key_text(struct onak_dbctx *dbctx, const char *search,
                                &cursor,
                                0);   /* flags */
 
+               if (ret != 0) {
+                       db4_endtrans(dbctx);
+                       break;
+               }
+
                memset(&key, 0, sizeof(key));
                memset(&data, 0, sizeof(data));
                key.data = curword->object;
@@ -488,7 +499,7 @@ static int db4_fetch_key_text(struct onak_dbctx *dbctx, const char *search,
                        free(data.data);
                        data.data = NULL;
                }
-               ret = cursor->c_close(cursor);
+               cursor->c_close(cursor);
                cursor = NULL;
                firstpass = 0;
                db4_endtrans(dbctx);
@@ -530,6 +541,10 @@ static int db4_fetch_key_skshash(struct onak_dbctx *dbctx,
                        &cursor,
                        0);   /* flags */
 
+       if (ret != 0) {
+               return 0;
+       }
+
        memset(&key, 0, sizeof(key));
        memset(&data, 0, sizeof(data));
        key.data = (void *) hash->hash;
@@ -550,7 +565,7 @@ static int db4_fetch_key_skshash(struct onak_dbctx *dbctx,
                }
        }
 
-       ret = cursor->c_close(cursor);
+       cursor->c_close(cursor);
        cursor = NULL;
 
        return db4_fetch_key_id(dbctx, keyid, publickey, false);
@@ -600,7 +615,7 @@ static int db4_delete_key(struct onak_dbctx *dbctx,
                        wordlist = makewordlist(wordlist, uids[i]);
                }
 
-               ret = privctx->worddb->cursor(privctx->worddb,
+               privctx->worddb->cursor(privctx->worddb,
                        privctx->txn,
                        &cursor,
                        0);   /* flags */
@@ -651,44 +666,46 @@ static int db4_delete_key(struct onak_dbctx *dbctx,
                                }
                        }
                }
-               ret = cursor->c_close(cursor);
+               cursor->c_close(cursor);
                cursor = NULL;
 
                ret = privctx->skshashdb->cursor(privctx->skshashdb,
                        privctx->txn,
                        &cursor,
                        0);   /* flags */
-               get_skshash(publickey, &hash);
+               if (ret == 0) {
+                       get_skshash(publickey, &hash);
 
-               memset(&key, 0, sizeof(key));
-               memset(&data, 0, sizeof(data));
-               key.data = hash.hash;
-               key.size = sizeof(hash.hash);
-               data.data = &keyid;
-               data.size = sizeof(keyid);
+                       memset(&key, 0, sizeof(key));
+                       memset(&data, 0, sizeof(data));
+                       key.data = hash.hash;
+                       key.size = sizeof(hash.hash);
+                       data.data = &keyid;
+                       data.size = sizeof(keyid);
 
-               ret = cursor->c_get(cursor,
-                       &key,
-                       &data,
-                       DB_GET_BOTH);
+                       ret = cursor->c_get(cursor,
+                               &key,
+                               &data,
+                               DB_GET_BOTH);
 
-               if (ret == 0) {
-                       ret = cursor->c_del(cursor, 0);
-               }
+                       if (ret == 0) {
+                               ret = cursor->c_del(cursor, 0);
+                       }
 
-               if (ret != 0) {
-                       logthing(LOGTHING_ERROR,
-                               "Problem deleting skshash: %s "
-                               "(0x%016" PRIX64 ")",
-                               db_strerror(ret),
-                               keyid);
-                       if (ret == DB_LOCK_DEADLOCK) {
-                               deadlock = true;
+                       if (ret != 0) {
+                               logthing(LOGTHING_ERROR,
+                                       "Problem deleting skshash: %s "
+                                       "(0x%016" PRIX64 ")",
+                                       db_strerror(ret),
+                                       keyid);
+                               if (ret == DB_LOCK_DEADLOCK) {
+                                       deadlock = true;
+                               }
                        }
-               }
 
-               ret = cursor->c_close(cursor);
-               cursor = NULL;
+                       cursor->c_close(cursor);
+                       cursor = NULL;
+               }
 
                /*
                 * Free our UID and word lists.
@@ -705,7 +722,7 @@ static int db4_delete_key(struct onak_dbctx *dbctx,
        }
 
        if (!deadlock) {
-               ret = privctx->id32db->cursor(privctx->id32db,
+               privctx->id32db->cursor(privctx->id32db,
                        privctx->txn,
                        &cursor,
                        0);   /* flags */
@@ -791,9 +808,8 @@ static int db4_delete_key(struct onak_dbctx *dbctx,
                        free(subkeyids);
                        subkeyids = NULL;
                }
-               ret = cursor->c_close(cursor);
+               cursor->c_close(cursor);
                cursor = NULL;
-
        }
 
        if (!deadlock) {
@@ -1129,6 +1145,10 @@ static int db4_iterate_keys(struct onak_dbctx *dbctx,
                        &cursor,
                        0);   /* flags */
 
+               if (ret != 0) {
+                       continue;
+               }
+
                memset(&dbkey, 0, sizeof(dbkey));
                memset(&data, 0, sizeof(data));
                ret = cursor->c_get(cursor, &dbkey, &data, DB_NEXT);
@@ -1159,7 +1179,7 @@ static int db4_iterate_keys(struct onak_dbctx *dbctx,
                                db_strerror(ret));
                }
 
-               ret = cursor->c_close(cursor);
+               cursor->c_close(cursor);
                cursor = NULL;
        }
 
@@ -1371,8 +1391,10 @@ struct onak_dbctx *keydb_db4_init(bool readonly)
                                        "Error opening db environment: %s (%s)",
                                        config.db_dir,
                                        db_strerror(ret));
-                       privctx->dbenv->close(privctx->dbenv, 0);
-                       privctx->dbenv = NULL;
+                       if (privctx->dbenv != NULL) {
+                               privctx->dbenv->close(privctx->dbenv, 0);
+                               privctx->dbenv = NULL;
+                       }
                }
        }
 
index 9e072bab0f240e9205668c03769032711627e2a6..a1529456548804a55efc02d98274e1d2c859f14c 100644 (file)
@@ -452,7 +452,7 @@ static struct ll *internal_get_key_by_word(char *word, struct ll *mct)
        d = opendir(buffer);
        logthing(LOGTHING_DEBUG, "Scanning for word %s in dir %s", word,
                 buffer);
-       if (d)
+       if (d) {
                do {
                        de = readdir(d);
                        if (de && de->d_name[0] != '.') {
@@ -470,7 +470,8 @@ static struct ll *internal_get_key_by_word(char *word, struct ll *mct)
                                }
                        }
                } while (de);
-       closedir(d);
+               closedir(d);
+       }
 
        return keys;
 }
@@ -640,10 +641,9 @@ struct onak_dbctx *keydb_fs_init(bool readonly)
                privctx->lockfile_fd = open(buffer, O_RDWR | O_CREAT, 0600);
        }
        chdir(config.db_dir);
-       if (privctx->lockfile_fd == -1)
-               privctx->lockfile_fd = open(buffer,
-                                        (privctx->lockfile_readonly) ?
-                                        O_RDONLY : O_RDWR);
+       privctx->lockfile_fd = open(buffer,
+                                (privctx->lockfile_readonly) ?
+                                O_RDONLY : O_RDWR);
        if (privctx->lockfile_fd == -1)
                privctx->lockfile_fd = open(buffer, O_RDWR | O_CREAT, 0600);
        if (privctx->lockfile_fd == -1) {
index 7c7b31a4a50e75bc7acc290bb6333e81c8c07cf7..8bb8c02bd2e3a5b5ccc504ecd36d856ad12899bb 100644 (file)
@@ -52,7 +52,7 @@ static int hkp_parse_url(struct onak_hkp_dbctx *privctx, const char *url)
                        &port);
        if (matched < 2) {
                proto[0] = 0;
-               matched = sscanf(url, "%256[a-zA-Z0-9.]:%u", host, &port);
+               sscanf(url, "%256[a-zA-Z0-9.]:%u", host, &port);
        }
 
        if (host[0] == 0) {
index 5fd084398d048568df01867785f24453c93304a4..1d10928fdec80146304ec50299329bb4d99662ae 100644 (file)
@@ -489,7 +489,6 @@ static void keyd_cleanupdb(struct onak_dbctx *dbctx)
                logthing(LOGTHING_NOTICE, "Error closing down socket: %d",
                                errno);
        }
-       keyd_fd = -1;
 
        free(dbctx);
 
@@ -559,6 +558,13 @@ struct onak_dbctx *keydb_keyd_init(bool readonly)
                        }
 
                        count = read(keyd_fd, &reply, sizeof(reply));
+                       if (count != sizeof(reply)) {
+                               logthing(LOGTHING_CRITICAL,
+                                       "Error! Unexpected keyd version "
+                                       "length: %d != %d",
+                                       count, sizeof(reply));
+                               exit(EXIT_FAILURE);
+                       }
                        logthing(LOGTHING_DEBUG,
                                        "keyd protocol version %d",
                                        reply);
index 47492c59e26c887474cf125b6024cea1a3de2bf5..ef942dbd92d78635d1b31b5f6a78ccd021fc7ddf 100644 (file)
--- a/keydctl.c
+++ b/keydctl.c
@@ -154,10 +154,17 @@ static void keyd_status(void)
        uint32_t reply;
        struct keyd_stats stats;
 
-       keyd_do_command(KEYD_CMD_VERSION, &reply, sizeof(reply));
+       if (keyd_do_command(KEYD_CMD_VERSION, &reply, sizeof(reply)) == -1) {
+               printf("Got failure asking for keyd version.\n");
+               return;
+       }
        printf("Using keyd protocol version %d.\n", reply);
 
-       keyd_do_command(KEYD_CMD_STATS, &stats, sizeof(stats));
+       if (keyd_do_command(KEYD_CMD_STATS, &stats, sizeof(stats)) == -1) {
+               printf("Got failure asking for keyd statistics.\n");
+               return;
+       }
+
        printf("keyd running since %s", ctime(&stats.started));
        printf("%d client connections received\n", stats.connects);
 
index fbd5a177deed76eb30139ebd8a5d85cd8abd7adf..0932df31669b98034affda15fa0eb9ba5fc55f44 100644 (file)
--- a/maxpath.c
+++ b/maxpath.c
@@ -91,12 +91,16 @@ int main(int argc, char *argv[])
        while ((optchar = getopt(argc, argv, "c:")) != -1 ) {
                switch (optchar) {
                case 'c':
+                       if (configfile != NULL) {
+                               free(configfile);
+                       }
                        configfile = strdup(optarg);
                        break;
                }
        }
 
        readconfig(configfile);
+       free(configfile);
        initlogthing("maxpath", config.logfile);
        dbctx = config.dbinit(true);
        if (dbctx != NULL) {
diff --git a/onak.c b/onak.c
index dd39bb3757fb2992e288923b5bb40f570160b48c..7a5d693cc9b89904e2f97762deb5d579537b5c6e 100644 (file)
--- a/onak.c
+++ b/onak.c
@@ -166,7 +166,6 @@ int main(int argc, char *argv[])
        int                              i;
        bool                             ishex = false;
        bool                             isfp = false;
-       bool                             verbose = false;
        bool                             update = false;
        bool                             binary = false;
        bool                             fingerprint = false;
@@ -194,7 +193,6 @@ int main(int argc, char *argv[])
                        update = true;
                        break;
                case 'v': 
-                       verbose = true;
                        setlogthreshold(LOGTHING_INFO);
                        break;
                }
index f780520c9c7f5a9e251217370970d3785bcb4176..ed61e24d16be5e556a527cfbfa80bc4f10e6beaa 100644 (file)
@@ -194,7 +194,6 @@ onak_status_t read_openpgp_stream(int (*getchar_func)(void *ctx, size_t count,
        struct openpgp_packet_list      *curpacket = NULL, **packetend = NULL;
        onak_status_t                    rc = ONAK_E_OK;
        int                              keys = 0;
-       bool                             inpacket = false;
 
        if (packets == NULL)
                return ONAK_E_INVALID_PARAM;
@@ -206,14 +205,12 @@ onak_status_t read_openpgp_stream(int (*getchar_func)(void *ctx, size_t count,
                }
        }
 
-       while (!rc && (maxnum == 0 || keys < maxnum) &&
+       while (rc == ONAK_E_OK && (maxnum == 0 || keys < maxnum) &&
                        !getchar_func(ctx, 1, &curchar)) {
-               if (!inpacket && (curchar & 0x80)) {
+               if (curchar & 0x80) {
                        /*
-                        * New packet. Record the fact we're in a packet and
-                        * allocate memory for it.
+                        * New packet. Allocate memory for it.
                         */
-                       inpacket = true;
                        if (curpacket != NULL) {
                                curpacket->next = malloc(sizeof (*curpacket));
                                packetend = &curpacket->next;
@@ -236,7 +233,10 @@ onak_status_t read_openpgp_stream(int (*getchar_func)(void *ctx, size_t count,
                         */
                        if (curpacket->packet->newformat) {
                                curpacket->packet->tag = (curchar & 0x3F);
-                               rc = getchar_func(ctx, 1, &curchar);
+                               if (getchar_func(ctx, 1, &curchar)) {
+                                       rc = ONAK_E_INVALID_PKT;
+                                       break;
+                               }
                                curpacket->packet->length = curchar;
                                if (curpacket->packet->length > 191 &&
                                        curpacket->packet->length < 224) {
@@ -255,43 +255,76 @@ onak_status_t read_openpgp_stream(int (*getchar_func)(void *ctx, size_t count,
                                         * 5 byte length; ie 255 followed by 3
                                         * bytes of MSB length.
                                         */
-                                       rc = getchar_func(ctx, 1, &curchar);
+                                       if (getchar_func(ctx, 1, &curchar)) {
+                                               rc = ONAK_E_INVALID_PKT;
+                                               break;
+                                       }
                                        curpacket->packet->length = curchar;
                                        curpacket->packet->length <<= 8;
-                                       rc = getchar_func(ctx, 1, &curchar);
+                                       if (getchar_func(ctx, 1, &curchar)) {
+                                               rc = ONAK_E_INVALID_PKT;
+                                               break;
+                                       }
                                        curpacket->packet->length += curchar;
                                        curpacket->packet->length <<= 8;
-                                       rc = getchar_func(ctx, 1, &curchar);
+                                       if (getchar_func(ctx, 1, &curchar)) {
+                                               rc = ONAK_E_INVALID_PKT;
+                                               break;
+                                       }
                                        curpacket->packet->length += curchar;
                                        curpacket->packet->length <<= 8;
-                                       rc = getchar_func(ctx, 1, &curchar);
+                                       if (getchar_func(ctx, 1, &curchar)) {
+                                               rc = ONAK_E_INVALID_PKT;
+                                               break;
+                                       }
                                        curpacket->packet->length += curchar;
                                }
                        } else {
                                curpacket->packet->tag = (curchar & 0x3C) >> 2;
                                switch (curchar & 3) {
                                case 0:
-                                       rc = getchar_func(ctx, 1, &curchar);
+                                       if (getchar_func(ctx, 1, &curchar)) {
+                                               rc = ONAK_E_INVALID_PKT;
+                                               break;
+                                       }
                                        curpacket->packet->length = curchar;
                                        break;
                                case 1:
-                                       rc = getchar_func(ctx, 1, &curchar);
+                                       if (getchar_func(ctx, 1, &curchar)) {
+                                               rc = ONAK_E_INVALID_PKT;
+                                               break;
+                                       }
                                        curpacket->packet->length = curchar;
                                        curpacket->packet->length <<= 8;
-                                       rc = getchar_func(ctx, 1, &curchar);
+                                       if (getchar_func(ctx, 1, &curchar)) {
+                                               rc = ONAK_E_INVALID_PKT;
+                                               break;
+                                       }
                                        curpacket->packet->length += curchar;
                                        break;
                                case 2:
-                                       rc = getchar_func(ctx, 1, &curchar);
+                                       if (getchar_func(ctx, 1, &curchar)) {
+                                               rc = ONAK_E_INVALID_PKT;
+                                               break;
+                                       }
                                        curpacket->packet->length = 
                                                (curchar << 24);
-                                       rc = getchar_func(ctx, 1, &curchar);
+                                       if (getchar_func(ctx, 1, &curchar)) {
+                                               rc = ONAK_E_INVALID_PKT;
+                                               break;
+                                       }
                                        curpacket->packet->length +=
                                                (curchar << 16);
-                                       rc = getchar_func(ctx, 1, &curchar);
+                                       if (getchar_func(ctx, 1, &curchar)) {
+                                               rc = ONAK_E_INVALID_PKT;
+                                               break;
+                                       }
                                        curpacket->packet->length +=
                                                (curchar << 8);
-                                       rc = getchar_func(ctx, 1, &curchar);
+                                       if (getchar_func(ctx, 1, &curchar)) {
+                                               rc = ONAK_E_INVALID_PKT;
+                                               break;
+                                       }
                                        curpacket->packet->length += curchar;
                                        break;
                                case 3:
@@ -318,7 +351,6 @@ onak_status_t read_openpgp_stream(int (*getchar_func)(void *ctx, size_t count,
                                                curpacket->packet->data);
                                }
                        }
-                       inpacket = false;
                } else {
                        rc = ONAK_E_INVALID_PKT;
                }
index a842230c4c9bbc808754410e3908d19a57c23169..b806c3e50f59a9cb1431e46a646e628a19f3cbde 100644 (file)
@@ -119,7 +119,7 @@ void sixdegrees(struct onak_dbctx *dbctx, uint64_t keyid)
         * if it's signed by the key we're looking at.
         */
        initcolour(false);
-       degree = countdegree(dbctx, keyinfo, true, 7);
+       countdegree(dbctx, keyinfo, true, 7);
 
        puts("\t\tSigned by\t\tSigns");
        for (loop = 1; loop < 7; loop++) {
@@ -143,6 +143,9 @@ int main(int argc, char *argv[])
        while ((optchar = getopt(argc, argv, "c:")) != -1 ) {
                switch (optchar) {
                case 'c':
+                       if (configfile != NULL) {
+                               free(configfile);
+                       }
                        configfile = strdup(optarg);
                        break;
                }
@@ -153,6 +156,7 @@ int main(int argc, char *argv[])
        }
 
        readconfig(configfile);
+       free(configfile);
        initlogthing("sixdegrees", config.logfile);
        dbctx = config.dbinit(true);
        if (dbctx != NULL) {