summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefano Esposito <stefano.esposito87@gmail.com>2007-09-11 22:27:55 +0200
committerDan McGee <dan@archlinux.org>2007-09-17 21:59:02 -0500
commitd50390c089c23ca20c23febc45ea8b9cc24e70f0 (patch)
tree02743e3ab5af43e6778d184c3e5fb749d6625e9f
parent82a1129539ee6c1a87ffbe816a0c8c42f3469177 (diff)
downloadpacman-d50390c089c23ca20c23febc45ea8b9cc24e70f0.tar.xz
Avoid segfaults whet calling alpm_option_get_* before initialization
When calling a function of the alpm_option_get_* group, you get a segfault if you don't call alpm_initialize() first. With this patch those functions set pm_errno to PM_ERR_HANDLE_NULL and return an error value if handle == NULL. (Dan: modified to meet pacman coding standards) Signed-off-by: Stefano Esposito <stefano.esposito87@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--lib/libalpm/handle.c183
1 files changed, 164 insertions, 19 deletions
diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c
index ea252adb..e8f21473 100644
--- a/lib/libalpm/handle.c
+++ b/lib/libalpm/handle.c
@@ -102,31 +102,176 @@ void _alpm_handle_free(pmhandle_t *handle)
FREE(handle);
}
-alpm_cb_log SYMEXPORT alpm_option_get_logcb() { return (handle ? handle->logcb : NULL); }
-alpm_cb_download SYMEXPORT alpm_option_get_dlcb() { return (handle ? handle->dlcb : NULL); }
-const char SYMEXPORT *alpm_option_get_root() { return handle->root; }
-const char SYMEXPORT *alpm_option_get_dbpath() { return handle->dbpath; }
-alpm_list_t SYMEXPORT *alpm_option_get_cachedirs() { return handle->cachedirs; }
-const char SYMEXPORT *alpm_option_get_logfile() { return handle->logfile; }
-const char SYMEXPORT *alpm_option_get_lockfile() { return handle->lockfile; }
-unsigned short SYMEXPORT alpm_option_get_usesyslog() { return handle->usesyslog; }
-alpm_list_t SYMEXPORT *alpm_option_get_noupgrades() { return handle->noupgrade; }
-alpm_list_t SYMEXPORT *alpm_option_get_noextracts() { return handle->noextract; }
-alpm_list_t SYMEXPORT *alpm_option_get_ignorepkgs() { return handle->ignorepkg; }
-alpm_list_t SYMEXPORT *alpm_option_get_holdpkgs() { return handle->holdpkg; }
-time_t SYMEXPORT alpm_option_get_upgradedelay() { return handle->upgradedelay; }
-const char SYMEXPORT *alpm_option_get_xfercommand() { return handle->xfercommand; }
-unsigned short SYMEXPORT alpm_option_get_nopassiveftp() { return handle->nopassiveftp; }
-
-pmdb_t SYMEXPORT *alpm_option_get_localdb() { return handle->db_local; }
+alpm_cb_log SYMEXPORT alpm_option_get_logcb()
+{
+ if (handle == NULL) {
+ pm_errno = PM_ERR_HANDLE_NULL;
+ return NULL;
+ }
+ return handle->logcb;
+}
+
+alpm_cb_download SYMEXPORT alpm_option_get_dlcb()
+{
+ if (handle == NULL) {
+ pm_errno = PM_ERR_HANDLE_NULL;
+ return NULL;
+ }
+ return handle->dlcb;
+}
+
+const char SYMEXPORT *alpm_option_get_root()
+{
+ if (handle == NULL) {
+ pm_errno = PM_ERR_HANDLE_NULL;
+ return NULL;
+ }
+ return handle->root;
+}
+
+const char SYMEXPORT *alpm_option_get_dbpath()
+{
+ if (handle == NULL) {
+ pm_errno = PM_ERR_HANDLE_NULL;
+ return NULL;
+ }
+ return handle->dbpath;
+}
+
+alpm_list_t SYMEXPORT *alpm_option_get_cachedirs()
+{
+ if (handle == NULL) {
+ pm_errno = PM_ERR_HANDLE_NULL;
+ return NULL;
+ }
+ return handle->cachedirs;
+}
+
+const char SYMEXPORT *alpm_option_get_logfile()
+{
+ if (handle == NULL) {
+ pm_errno = PM_ERR_HANDLE_NULL;
+ return NULL;
+ }
+ return handle->logfile;
+}
+
+const char SYMEXPORT *alpm_option_get_lockfile()
+{
+ if (handle == NULL) {
+ pm_errno = PM_ERR_HANDLE_NULL;
+ return NULL;
+ }
+ return handle->lockfile;
+}
+
+unsigned short SYMEXPORT alpm_option_get_usesyslog()
+{
+ if (handle == NULL) {
+ pm_errno = PM_ERR_HANDLE_NULL;
+ return -1;
+ }
+ return handle->usesyslog;
+}
+
+alpm_list_t SYMEXPORT *alpm_option_get_noupgrades()
+{
+ if (handle == NULL) {
+ pm_errno = PM_ERR_HANDLE_NULL;
+ return NULL;
+ }
+ return handle->noupgrade;
+}
+
+alpm_list_t SYMEXPORT *alpm_option_get_noextracts()
+{
+ if (handle == NULL) {
+ pm_errno = PM_ERR_HANDLE_NULL;
+ return NULL;
+ }
+ return handle->noextract;
+}
+
+alpm_list_t SYMEXPORT *alpm_option_get_ignorepkgs()
+{
+ if (handle == NULL) {
+ pm_errno = PM_ERR_HANDLE_NULL;
+ return NULL;
+ }
+ return handle->ignorepkg;
+}
+
+alpm_list_t SYMEXPORT *alpm_option_get_holdpkgs()
+{
+ if (handle == NULL) {
+ pm_errno = PM_ERR_HANDLE_NULL;
+ return NULL;
+ }
+ return handle->holdpkg;
+}
+
+time_t SYMEXPORT alpm_option_get_upgradedelay()
+{
+ if (handle == NULL) {
+ pm_errno = PM_ERR_HANDLE_NULL;
+ return -1;
+ }
+ return handle->upgradedelay;
+}
+
+const char SYMEXPORT *alpm_option_get_xfercommand()
+{
+ if (handle == NULL) {
+ pm_errno = PM_ERR_HANDLE_NULL;
+ return NULL;
+ }
+ return handle->xfercommand;
+}
+
+unsigned short SYMEXPORT alpm_option_get_nopassiveftp()
+{
+ if (handle == NULL) {
+ pm_errno = PM_ERR_HANDLE_NULL;
+ return -1;
+ }
+ return handle->nopassiveftp;
+}
+
+pmdb_t SYMEXPORT *alpm_option_get_localdb()
+{
+ if (handle == NULL) {
+ pm_errno = PM_ERR_HANDLE_NULL;
+ return NULL;
+ }
+ return handle->db_local;
+}
+
alpm_list_t SYMEXPORT *alpm_option_get_syncdbs()
{
+ if (handle == NULL) {
+ pm_errno = PM_ERR_HANDLE_NULL;
+ return NULL;
+ }
return handle->dbs_sync;
}
-void SYMEXPORT alpm_option_set_logcb(alpm_cb_log cb) { handle->logcb = cb; }
+void SYMEXPORT alpm_option_set_logcb(alpm_cb_log cb)
+{
+ if (handle == NULL) {
+ pm_errno = PM_ERR_HANDLE_NULL;
+ return;
+ }
+ handle->logcb = cb;
+}
-void SYMEXPORT alpm_option_set_dlcb(alpm_cb_download cb) { handle->dlcb = cb; }
+void SYMEXPORT alpm_option_set_dlcb(alpm_cb_download cb)
+{
+ if (handle == NULL) {
+ pm_errno = PM_ERR_HANDLE_NULL;
+ return;
+ }
+ handle->dlcb = cb;
+}
int SYMEXPORT alpm_option_set_root(const char *root)
{