]> git.ipfire.org Git - thirdparty/libsolv.git/commitdiff
Report unsupported compression in solv_xfopen() with errno 563/head
authorPetr Písař <ppisar@redhat.com>
Mon, 13 May 2024 07:55:01 +0000 (09:55 +0200)
committerPetr Písař <ppisar@redhat.com>
Wed, 15 May 2024 14:55:55 +0000 (16:55 +0200)
If libsolv was built without Zstandard support and "primary.xml.zst"
was passed solv_xfopen(), solv_xfopen() returned 0 without setting
errno. A calling application could not distinguish an unsupported
compression format from other I/O errors.

This patch improves this situation by setting errno variable to an
appropriate value. The value macros are documented in POSIX 2017.

ext/solv_xfopen.c

index 369003b4bc08489c30da3b658f207d7e66f2965a..e23ea5963faaacbc645101c4c2c0ab5d72743ff4 100644 (file)
@@ -11,6 +11,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <fcntl.h>
+#include <errno.h>
 
 #ifdef _WIN32
   #include "fmemopen.c"
@@ -660,7 +661,10 @@ solv_xfopen(const char *fn, const char *mode)
   char *suf;
 
   if (!fn)
-    return 0;
+    {
+      errno = EINVAL;
+      return 0;
+    }
   if (!mode)
     mode = "r";
   suf = strrchr(fn, '.');
@@ -669,7 +673,10 @@ solv_xfopen(const char *fn, const char *mode)
     return mygzfopen(fn, mode);
 #else
   if (suf && !strcmp(suf, ".gz"))
-    return 0;
+    {
+      errno = ENOTSUP;
+      return 0;
+    }
 #endif
 #ifdef ENABLE_LZMA_COMPRESSION
   if (suf && !strcmp(suf, ".xz"))
@@ -678,30 +685,45 @@ solv_xfopen(const char *fn, const char *mode)
     return mylzfopen(fn, mode);
 #else
   if (suf && !strcmp(suf, ".xz"))
-    return 0;
+    {
+      errno = ENOTSUP;
+      return 0;
+    }
   if (suf && !strcmp(suf, ".lzma"))
-    return 0;
+    {
+      errno = ENOTSUP;
+      return 0;
+    }
 #endif
 #ifdef ENABLE_BZIP2_COMPRESSION
   if (suf && !strcmp(suf, ".bz2"))
     return mybzfopen(fn, mode);
 #else
   if (suf && !strcmp(suf, ".bz2"))
-    return 0;
+    {
+      errno = ENOTSUP;
+      return 0;
+    }
 #endif
 #ifdef ENABLE_ZSTD_COMPRESSION
   if (suf && !strcmp(suf, ".zst"))
     return myzstdfopen(fn, mode);
 #else
   if (suf && !strcmp(suf, ".zst"))
-    return 0;
+    {
+      errno = ENOTSUP;
+      return 0;
+    }
 #endif
 #ifdef ENABLE_ZCHUNK_COMPRESSION
   if (suf && !strcmp(suf, ".zck"))
     return myzchunkfopen(fn, mode);
 #else
   if (suf && !strcmp(suf, ".zck"))
-    return 0;
+    {
+      errno = ENOTSUP;
+      return 0;
+    }
 #endif
   return fopen(fn, mode);
 }