Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib/libalpm/db.c
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-06-14 10:01:08 -0500
committerDan McGee <dan@archlinux.org>2011-06-14 10:01:08 -0500
commitee015f086f3c40390659bbc0129b7c08ffd0ed5f (patch)
treeb2ba33041450fd5c5fb226649b88534fdac60ff1 /lib/libalpm/db.c
parentbe972767358e6dfbb08686555d8e2c0176a55106 (diff)
Ensure handle is valid and pm_errno is reset when calling into API
We didn't do due diligence before and ensure prior pm_errno values weren't influencing what happened in further ALPM calls. I observed one case of early setup code setting pm_errno to PM_ERR_WRONG_ARGS and that flag persisting the entire time we were calling library code. Add a new CHECK_HANDLE() macro that does two things: 1) ensures the handle variable passed to it is non-NULL and 2) clears any existing pm_errno flag set on the handle. This macro can replace many places we used the ASSERT(handle != NULL, ...) pattern before. Several other other places only need a simple 'set to zero' of the pm_errno field. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/db.c')
-rw-r--r--lib/libalpm/db.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c
index 0584a36f..c3a7abd2 100644
--- a/lib/libalpm/db.c
+++ b/lib/libalpm/db.c
@@ -48,7 +48,7 @@
pmdb_t SYMEXPORT *alpm_db_register_sync(pmhandle_t *handle, const char *treename)
{
/* Sanity checks */
- ASSERT(handle != NULL, return NULL);
+ CHECK_HANDLE(handle, return NULL);
ASSERT(treename != NULL && strlen(treename) != 0,
RET_ERR(handle, PM_ERR_WRONG_ARGS, NULL));
/* Do not register a database if a transaction is on-going */
@@ -75,7 +75,7 @@ int SYMEXPORT alpm_db_unregister_all(pmhandle_t *handle)
pmdb_t *db;
/* Sanity checks */
- ASSERT(handle != NULL, return -1);
+ CHECK_HANDLE(handle, return -1);
/* Do not unregister a database if a transaction is on-going */
ASSERT(handle->trans == NULL, RET_ERR(handle, PM_ERR_TRANS_NOT_NULL, -1));
@@ -99,6 +99,7 @@ int SYMEXPORT alpm_db_unregister(pmdb_t *db)
ASSERT(db != NULL, return -1);
/* Do not unregister a database if a transaction is on-going */
handle = db->handle;
+ handle->pm_errno = 0;
ASSERT(handle->trans == NULL, RET_ERR(handle, PM_ERR_TRANS_NOT_NULL, -1));
if(db == handle->db_local) {
@@ -165,6 +166,7 @@ int SYMEXPORT alpm_db_add_server(pmdb_t *db, const char *url)
/* Sanity checks */
ASSERT(db != NULL, return -1);
+ db->handle->pm_errno = 0;
ASSERT(url != NULL && strlen(url) != 0, RET_ERR(db->handle, PM_ERR_WRONG_ARGS, -1));
newurl = sanitize_url(url);
@@ -190,6 +192,7 @@ int SYMEXPORT alpm_db_remove_server(pmdb_t *db, const char *url)
/* Sanity checks */
ASSERT(db != NULL, return -1);
+ db->handle->pm_errno = 0;
ASSERT(url != NULL && strlen(url) != 0, RET_ERR(db->handle, PM_ERR_WRONG_ARGS, -1));
newurl = sanitize_url(url);
@@ -216,6 +219,7 @@ int SYMEXPORT alpm_db_set_pgp_verify(pmdb_t *db, pgp_verify_t verify)
{
/* Sanity checks */
ASSERT(db != NULL, return -1);
+ db->handle->pm_errno = 0;
db->pgp_verify = verify;
_alpm_log(db->handle, PM_LOG_DEBUG, "adding VerifySig option to database '%s': %d\n",
@@ -235,7 +239,9 @@ const char SYMEXPORT *alpm_db_get_name(const pmdb_t *db)
pmpkg_t SYMEXPORT *alpm_db_get_pkg(pmdb_t *db, const char *name)
{
ASSERT(db != NULL, return NULL);
- ASSERT(name != NULL && strlen(name) != 0, return NULL);
+ db->handle->pm_errno = 0;
+ ASSERT(name != NULL && strlen(name) != 0,
+ RET_ERR(db->handle, PM_ERR_WRONG_ARGS, NULL));
return _alpm_db_get_pkgfromcache(db, name);
}
@@ -244,6 +250,7 @@ pmpkg_t SYMEXPORT *alpm_db_get_pkg(pmdb_t *db, const char *name)
alpm_list_t SYMEXPORT *alpm_db_get_pkgcache(pmdb_t *db)
{
ASSERT(db != NULL, return NULL);
+ db->handle->pm_errno = 0;
return _alpm_db_get_pkgcache(db);
}
@@ -251,7 +258,9 @@ alpm_list_t SYMEXPORT *alpm_db_get_pkgcache(pmdb_t *db)
pmgrp_t SYMEXPORT *alpm_db_readgrp(pmdb_t *db, const char *name)
{
ASSERT(db != NULL, return NULL);
- ASSERT(name != NULL && strlen(name) != 0, return NULL);
+ db->handle->pm_errno = 0;
+ ASSERT(name != NULL && strlen(name) != 0,
+ RET_ERR(db->handle, PM_ERR_WRONG_ARGS, NULL));
return _alpm_db_get_grpfromcache(db, name);
}
@@ -260,6 +269,7 @@ pmgrp_t SYMEXPORT *alpm_db_readgrp(pmdb_t *db, const char *name)
alpm_list_t SYMEXPORT *alpm_db_get_grpcache(pmdb_t *db)
{
ASSERT(db != NULL, return NULL);
+ db->handle->pm_errno = 0;
return _alpm_db_get_grpcache(db);
}
@@ -268,6 +278,7 @@ alpm_list_t SYMEXPORT *alpm_db_get_grpcache(pmdb_t *db)
alpm_list_t SYMEXPORT *alpm_db_search(pmdb_t *db, const alpm_list_t* needles)
{
ASSERT(db != NULL, return NULL);
+ db->handle->pm_errno = 0;
return _alpm_db_search(db, needles);
}
@@ -276,6 +287,7 @@ alpm_list_t SYMEXPORT *alpm_db_search(pmdb_t *db, const alpm_list_t* needles)
int SYMEXPORT alpm_db_set_pkgreason(pmdb_t *db, const char *name, pmpkgreason_t reason)
{
ASSERT(db != NULL, return -1);
+ db->handle->pm_errno = 0;
/* TODO assert db == db_local ? shouldn't need a db param at all here... */
ASSERT(name != NULL, RET_ERR(db->handle, PM_ERR_WRONG_ARGS, -1));