summaryrefslogtreecommitdiff
path: root/lib/libalpm/sync.c
diff options
context:
space:
mode:
authorAllan McRae <mcrae_allan@hotmail.com>2007-12-23 01:57:43 +1000
committerDan McGee <dan@archlinux.org>2007-12-28 19:46:21 -0600
commit14d6832ef24aeda7fe77cf4285538baa6e21670c (patch)
tree5e2cb671385c34ede6281c70937c46f355071e14 /lib/libalpm/sync.c
parentcca4ec647e6b5e1959206348360cc7412a5e8ed2 (diff)
downloadpacman-14d6832ef24aeda7fe77cf4285538baa6e21670c.tar.xz
Allow NULL parameter in alpm_trans_commit
Fixes FS#7380: alpm crashes on passing NULL to alpm_trans_commit in a sync operation. Adds check that data parameter is not NULL in several functions. Signed-off-by: Allan McRae <mcrae_allan@hotmail.com> [Dan: fix whitespace] Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/sync.c')
-rw-r--r--lib/libalpm/sync.c46
1 files changed, 28 insertions, 18 deletions
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index 76618665..22df9bf5 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -675,7 +675,11 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
if(deps) {
pm_errno = PM_ERR_UNSATISFIED_DEPS;
ret = -1;
- *data = deps;
+ if(data) {
+ *data = deps;
+ } else {
+ FREELIST(deps);
+ }
goto cleanup;
}
}
@@ -887,35 +891,41 @@ static int test_md5sum(pmtrans_t *trans, const char *filename,
md5sum2 = alpm_get_md5sum(filepath);
if(md5sum == NULL) {
- /* TODO wtf is this? malloc'd strings for error messages? */
- if((errormsg = calloc(512, sizeof(char))) == NULL) {
- RET_ERR(PM_ERR_MEMORY, -1);
+ if(data) {
+ /* TODO wtf is this? malloc'd strings for error messages? */
+ if((errormsg = calloc(512, sizeof(char))) == NULL) {
+ RET_ERR(PM_ERR_MEMORY, -1);
+ }
+ snprintf(errormsg, 512, _("can't get md5 checksum for file %s\n"),
+ filename);
+ *data = alpm_list_add(*data, errormsg);
}
- snprintf(errormsg, 512, _("can't get md5 checksum for file %s\n"),
- filename);
- *data = alpm_list_add(*data, errormsg);
ret = 1;
} else if(md5sum2 == NULL) {
- if((errormsg = calloc(512, sizeof(char))) == NULL) {
- RET_ERR(PM_ERR_MEMORY, -1);
+ if(data) {
+ if((errormsg = calloc(512, sizeof(char))) == NULL) {
+ RET_ERR(PM_ERR_MEMORY, -1);
+ }
+ snprintf(errormsg, 512, _("can't get md5 checksum for file %s\n"),
+ filename);
+ *data = alpm_list_add(*data, errormsg);
}
- snprintf(errormsg, 512, _("can't get md5 checksum for file %s\n"),
- filename);
- *data = alpm_list_add(*data, errormsg);
ret = 1;
} else if(strcmp(md5sum, md5sum2) != 0) {
int doremove = 0;
- if((errormsg = calloc(512, sizeof(char))) == NULL) {
- RET_ERR(PM_ERR_MEMORY, -1);
- }
QUESTION(trans, PM_TRANS_CONV_CORRUPTED_PKG, (char *)filename,
NULL, NULL, &doremove);
if(doremove) {
unlink(filepath);
}
- snprintf(errormsg, 512, _("file %s was corrupted (bad MD5 checksum)\n"),
- filename);
- *data = alpm_list_add(*data, errormsg);
+ if(data) {
+ if((errormsg = calloc(512, sizeof(char))) == NULL) {
+ RET_ERR(PM_ERR_MEMORY, -1);
+ }
+ snprintf(errormsg, 512, _("file %s was corrupted (bad MD5 checksum)\n"),
+ filename);
+ *data = alpm_list_add(*data, errormsg);
+ }
ret = 1;
}