hi.

i am playing with alpm and db4 to make a little program for me. just for fun.

and in this new release of libalpm (along pacman 3.2.0) i have found that 
alpm_list_remove behave differently than before. so the last parameter (void 
**data) need to be initialized to avoid a seg fault.

it happens in alpm_db_unregister if you unregister a sync db 
if you run this, you will see it happen

#include <stdio.h>
#include <stdlib.h>
#include <alpm.h>

int main(void) {
    pmdb_t *db;
    pmpkg_t *pkg;
    const char *s;

    alpm_initialize();
    alpm_option_set_root("/");
    alpm_option_set_dbpath("/var/lib/pacman");
    alpm_option_add_cachedir("/var/cache/pacman/pkg");
    alpm_option_set_logfile("/dev/stdout");
    db = alpm_db_register_sync("extra");
    puts("alpm_db_unregister(db)");
    alpm_db_unregister(db);
    puts("alpm_release()");
    alpm_release();
    exit(EXIT_SUCCESS);
}

i wonder how it has not generated more bug in libalpm.

so i check all uninitalised pointer in libalpm before alpm_list_remove and i 
found 3 occurences
see the patch

diff --git a/lib/libalpm/cache.c b/lib/libalpm/cache.c
index 032cc97..b7681db 100644
--- a/lib/libalpm/cache.c
+++ b/lib/libalpm/cache.c
@@ -135,7 +135,7 @@ int _alpm_db_add_pkgincache(pmdb_t *db, pmpkg_t *pkg)
 
 int _alpm_db_remove_pkgfromcache(pmdb_t *db, pmpkg_t *pkg)
 {
-       void *vdata;
+       void *vdata=NULL;
        pmpkg_t *data;
 
        ALPM_LOG_FUNC;
diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c
index d9a3931..c0d322c 100644
--- a/lib/libalpm/db.c
+++ b/lib/libalpm/db.c
@@ -145,7 +145,7 @@ int SYMEXPORT alpm_db_unregister(pmdb_t *db)
                 * databases by walking through the list returned by
                 * alpm_option_get_syncdbs, because the db is removed from that 
list here.
                 */
-               void *data;
+               void *data=NULL;
                handle->dbs_sync = alpm_list_remove(handle->dbs_sync,
                                db, _alpm_db_cmp, &data);
                if(data) {
diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c
index 864fafa..6ea16c0 100644
--- a/lib/libalpm/remove.c
+++ b/lib/libalpm/remove.c
@@ -118,7 +118,7 @@ static void remove_prepare_keep_needed(pmtrans_t *trans, 
pmdb_t *db,
                alpm_list_t *i;
                for(i = lp; i; i = i->next) {
                        pmdepmissing_t *miss = (pmdepmissing_t *)i->data;
-                       void *vpkg;
+                       void *vpkg=NULL;
                        pmpkg_t *pkg = _alpm_pkg_find(trans->packages, 
miss->causingpkg);
                        if(pkg == NULL) {
                                continue;


_______________________________________________
pacman-dev mailing list
[email protected]
http://archlinux.org/mailman/listinfo/pacman-dev

Reply via email to