]> git.ipfire.org Git - pakfire.git/commitdiff
compress: xfopen: Check for valid inputs
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 16 Mar 2021 17:59:48 +0000 (17:59 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 16 Mar 2021 17:59:48 +0000 (17:59 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/compress.c

index f92acea1e4731dbd371b8c5129d045be64d1c062..ffe870391f1e68be10ae7f75495ce6e44437a7c2 100644 (file)
@@ -18,6 +18,7 @@
 #                                                                             #
 #############################################################################*/
 
+#include <errno.h>
 #include <stdio.h>
 #include <string.h>
 
@@ -50,8 +51,21 @@ struct xz_cookie {
 FILE* pakfire_xfopen(FILE* f, const char* mode) {
        char buffer[MAX_MAGIC_LENGTH];
 
-       if (!f)
+       if (!f) {
+               errno = EBADFD;
                return NULL;
+       }
+
+       if (!mode) {
+               errno = EINVAL;
+               return NULL;
+       }
+
+       // This only works for reading files
+       if (*mode != 'r') {
+               errno = ENOTSUP;
+               return NULL;
+       }
 
        fpos_t pos;