1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-12-23 00:08:50 -05:00

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>
This commit is contained in:
Allan McRae 2007-12-23 01:57:43 +10:00 committed by Dan McGee
parent cca4ec647e
commit 14d6832ef2
2 changed files with 31 additions and 19 deletions

View File

@ -675,7 +675,11 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
if(deps) { if(deps) {
pm_errno = PM_ERR_UNSATISFIED_DEPS; pm_errno = PM_ERR_UNSATISFIED_DEPS;
ret = -1; ret = -1;
*data = deps; if(data) {
*data = deps;
} else {
FREELIST(deps);
}
goto cleanup; goto cleanup;
} }
} }
@ -887,35 +891,41 @@ static int test_md5sum(pmtrans_t *trans, const char *filename,
md5sum2 = alpm_get_md5sum(filepath); md5sum2 = alpm_get_md5sum(filepath);
if(md5sum == NULL) { if(md5sum == NULL) {
/* TODO wtf is this? malloc'd strings for error messages? */ if(data) {
if((errormsg = calloc(512, sizeof(char))) == NULL) { /* TODO wtf is this? malloc'd strings for error messages? */
RET_ERR(PM_ERR_MEMORY, -1); 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; ret = 1;
} else if(md5sum2 == NULL) { } else if(md5sum2 == NULL) {
if((errormsg = calloc(512, sizeof(char))) == NULL) { if(data) {
RET_ERR(PM_ERR_MEMORY, -1); 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; ret = 1;
} else if(strcmp(md5sum, md5sum2) != 0) { } else if(strcmp(md5sum, md5sum2) != 0) {
int doremove = 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, QUESTION(trans, PM_TRANS_CONV_CORRUPTED_PKG, (char *)filename,
NULL, NULL, &doremove); NULL, NULL, &doremove);
if(doremove) { if(doremove) {
unlink(filepath); unlink(filepath);
} }
snprintf(errormsg, 512, _("file %s was corrupted (bad MD5 checksum)\n"), if(data) {
filename); if((errormsg = calloc(512, sizeof(char))) == NULL) {
*data = alpm_list_add(*data, errormsg); 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; ret = 1;
} }

View File

@ -342,7 +342,9 @@ int _alpm_trans_addtarget(pmtrans_t *trans, char *target)
int _alpm_trans_prepare(pmtrans_t *trans, alpm_list_t **data) int _alpm_trans_prepare(pmtrans_t *trans, alpm_list_t **data)
{ {
*data = NULL; if(data) {
*data = NULL;
}
ALPM_LOG_FUNC; ALPM_LOG_FUNC;