From f7192b595881103f145a118d63d1b342ffd740b4 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Mon, 17 Nov 2008 21:47:55 -0600 Subject: Minor code cleanups Mostly noticed when compiling libalpm/pacman with ICC. Signed-off-by: Dan McGee --- lib/libalpm/be_files.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/libalpm/be_files.c') diff --git a/lib/libalpm/be_files.c b/lib/libalpm/be_files.c index f5d4e826..0658a661 100644 --- a/lib/libalpm/be_files.c +++ b/lib/libalpm/be_files.c @@ -51,7 +51,7 @@ * Return the last update time as number of seconds from the epoch. * Returns 0 if the value is unknown or can't be read. */ -time_t getlastupdate(const pmdb_t *db) +static time_t getlastupdate(const pmdb_t *db) { FILE *fp; char *file; @@ -85,7 +85,7 @@ time_t getlastupdate(const pmdb_t *db) /* * writes the dbpath/.lastupdate file with the value in time */ -int setlastupdate(const pmdb_t *db, time_t time) +static int setlastupdate(const pmdb_t *db, time_t time) { FILE *fp; char *file; @@ -500,7 +500,7 @@ int _alpm_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq) if(fgets(line, 512, fp) == NULL) { goto error; } - info->reason = atol(_alpm_strtrim(line)); + info->reason = (pmpkgreason_t)atol(_alpm_strtrim(line)); } else if(strcmp(line, "%SIZE%") == 0 || strcmp(line, "%CSIZE%") == 0) { /* NOTE: the CSIZE and SIZE fields both share the "size" field * in the pkginfo_t struct. This can be done b/c CSIZE -- cgit v1.2.3-54-g00ecf From b99bebc008dcf944a88f99bb44ac9029557e4149 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sun, 30 Nov 2008 17:17:00 -0600 Subject: Add regex to delta code so we don't segfault when reading line If the delta line doesn't match our regex, we won't go and process it, possibly walking off the end of the string. Signed-off-by: Dan McGee --- lib/libalpm/be_files.c | 5 ++++- lib/libalpm/delta.c | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) (limited to 'lib/libalpm/be_files.c') diff --git a/lib/libalpm/be_files.c b/lib/libalpm/be_files.c index 0658a661..b9ff6464 100644 --- a/lib/libalpm/be_files.c +++ b/lib/libalpm/be_files.c @@ -618,7 +618,10 @@ int _alpm_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq) _alpm_strtrim(line); if(strcmp(line, "%DELTAS%") == 0) { while(fgets(line, 512, fp) && strlen(_alpm_strtrim(line))) { - info->deltas = alpm_list_add(info->deltas, _alpm_delta_parse(line)); + pmdelta_t *delta = _alpm_delta_parse(line); + if(delta) { + info->deltas = alpm_list_add(info->deltas, delta); + } } } } diff --git a/lib/libalpm/delta.c b/lib/libalpm/delta.c index 22d9beb4..8dce7e3b 100644 --- a/lib/libalpm/delta.c +++ b/lib/libalpm/delta.c @@ -22,6 +22,8 @@ #include #include #include +#include +#include /* libalpm */ #include "delta.h" @@ -257,6 +259,19 @@ pmdelta_t *_alpm_delta_parse(char *line) { pmdelta_t *delta; char *tmp = line, *tmp2; + regex_t reg; + + regcomp(®, + "^[^[:space:]]* [[:xdigit:]]{32}" + " [^[:space:]]* [[:xdigit:]]{32}" + " [^[:space:]]* [[:xdigit:]]{32} [[:digit:]]*$", + REG_EXTENDED | REG_NOSUB | REG_NEWLINE); + if(regexec(®, line, 0, 0, 0) != 0) { + /* delta line is invalid, return NULL */ + regfree(®); + return(NULL); + } + regfree(®); CALLOC(delta, 1, sizeof(pmdelta_t), RET_ERR(PM_ERR_MEMORY, NULL)); -- cgit v1.2.3-54-g00ecf