]> git.ipfire.org Git - pakfire.git/commitdiff
packages: Validate UUIDs when reading from the database
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 16 Aug 2023 15:55:30 +0000 (15:55 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 16 Aug 2023 15:56:19 +0000 (15:56 +0000)
Since we are using the UUID in the filesystem paths, we must make sure
that no malicious content is in the field.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/include/pakfire/util.h
src/libpakfire/package.c
src/libpakfire/util.c

index 622fa3d7c39b8444746ed646f32de15d6a802361..e5d32acd0e124834ce610f97809274a584635249 100644 (file)
@@ -88,6 +88,9 @@ int pakfire_rmtree(const char* path, int flags);
        __pakfire_which(pakfire, path, sizeof(path), what)
 int __pakfire_which(struct pakfire* pakfire, char* path, const size_t length, const char* what);
 
+// UUID Stuff
+
+int pakfire_uuid_is_valid(const char* s);
 char* pakfire_generate_uuid(void);
 
 int pakfire_tty_is_noninteractive(void);
index a160a73011b292ff2385316c1a47268c99660162..af0f2362c9e53439000fb0c07fc6cbda5e70c9b6 100644 (file)
@@ -432,8 +432,6 @@ static int pakfire_package_make_cache_path(struct pakfire_package* pkg) {
                return 1;
        }
 
-       // XXX check if the UUID is valid
-
        return pakfire_cache_path(pkg->pakfire, pkg->cache_path, "%s/%s", uuid, filename);
 }
 
@@ -468,6 +466,13 @@ PAKFIRE_EXPORT const char* pakfire_package_get_string(
 
                case PAKFIRE_PKG_UUID:
                        ret = solvable_lookup_str(s, SOLVABLE_PKGID);
+
+                       // Validate the UUID
+                       if (!pakfire_uuid_is_valid(ret)) {
+                               errno = EINVAL;
+                               return NULL;
+                       }
+
                        break;
 
                case PAKFIRE_PKG_SUMMARY:
@@ -627,6 +632,11 @@ PAKFIRE_EXPORT int pakfire_package_set_string(
 
                case PAKFIRE_PKG_UUID:
                        id = SOLVABLE_PKGID;
+
+                       // Validate the UUID
+                       if (!pakfire_uuid_is_valid(value))
+                               return -EINVAL;
+
                        break;
 
                case PAKFIRE_PKG_SUMMARY:
index bb325a8063f6035a2b3f439d369a42a6c359f8c5..2faefe5739234fa76376fdfab3d1d59824f49c50 100644 (file)
@@ -438,6 +438,16 @@ char* pakfire_generate_uuid() {
        return ret;
 }
 
+int pakfire_uuid_is_valid(const char* s) {
+       uuid_t uuid;
+       int r;
+
+       // Check if we can parse the UUID
+       r = uuid_parse(s, uuid);
+
+       return (r == 0);
+}
+
 int pakfire_tty_is_noninteractive(void) {
        const int fds[] = {
                STDIN_FILENO,