From d50390c089c23ca20c23febc45ea8b9cc24e70f0 Mon Sep 17 00:00:00 2001 From: Stefano Esposito Date: Tue, 11 Sep 2007 22:27:55 +0200 Subject: 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 Signed-off-by: Dan McGee --- lib/libalpm/handle.c | 183 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 164 insertions(+), 19 deletions(-) (limited to 'lib/libalpm/handle.c') 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) { -- cgit v1.2.3-24-g4f1b