summaryrefslogtreecommitdiff
path: root/lib/libalpm/be_sync.c
diff options
context:
space:
mode:
authorAllan McRae <allan@archlinux.org>2013-06-06 13:47:26 +1000
committerAllan McRae <allan@archlinux.org>2013-06-06 13:47:26 +1000
commit9574bfd6c873d70e29a5003461b2d691f134c8ab (patch)
tree324d6f160f4f52c47e4c33aa73b76fbc473a21d9 /lib/libalpm/be_sync.c
parentcbbd3781c249c8318934fe0810a09546c2760f53 (diff)
parent450be928da1a71bebc3524f3f0bdb4160845b37e (diff)
downloadpacman-9574bfd6c873d70e29a5003461b2d691f134c8ab.tar.xz
Merge branch 'maint'
Diffstat (limited to 'lib/libalpm/be_sync.c')
-rw-r--r--lib/libalpm/be_sync.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c
index 1cbe055e..f9fd5d1f 100644
--- a/lib/libalpm/be_sync.c
+++ b/lib/libalpm/be_sync.c
@@ -479,6 +479,33 @@ cleanup:
return count;
}
+/* This function validates %FILENAME%. filename must be between 3 and
+ * PATH_MAX characters and cannot be contain a path */
+static int _alpm_validate_filename(alpm_db_t *db, const char *pkgname,
+ const char *filename)
+{
+ size_t len = strlen(filename);
+
+ if(filename[0] == '.') {
+ errno = EINVAL;
+ _alpm_log(db->handle, ALPM_LOG_ERROR, _("%s database is inconsistent: filename "
+ "of package %s is illegal\n"), db->treename, pkgname);
+ return -1;
+ } else if(memchr(filename, '/', len) != NULL) {
+ errno = EINVAL;
+ _alpm_log(db->handle, ALPM_LOG_ERROR, _("%s database is inconsistent: filename "
+ "of package %s is illegal\n"), db->treename, pkgname);
+ return -1;
+ } else if(len > PATH_MAX) {
+ errno = EINVAL;
+ _alpm_log(db->handle, ALPM_LOG_ERROR, _("%s database is inconsistent: filename "
+ "of package %s is too long\n"), db->treename, pkgname);
+ return -1;
+ }
+
+ return 0;
+}
+
#define READ_NEXT() do { \
if(_alpm_archive_fgets(archive, &buf) != ARCHIVE_OK) goto error; \
line = buf.line; \
@@ -558,6 +585,9 @@ static int sync_db_read(alpm_db_t *db, struct archive *archive,
}
} else if(strcmp(line, "%FILENAME%") == 0) {
READ_AND_STORE(pkg->filename);
+ if(_alpm_validate_filename(db, pkg->name, pkg->filename) < 0) {
+ return -1;
+ }
} else if(strcmp(line, "%DESC%") == 0) {
READ_AND_STORE(pkg->desc);
} else if(strcmp(line, "%GROUPS%") == 0) {