]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: do not use "re" with fmemopen 25059/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 19 Oct 2022 07:49:59 +0000 (09:49 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 19 Oct 2022 08:10:57 +0000 (10:10 +0200)
The man page says nothing about "e". Glibc clearly accepts it without fuss, but
it is meaningless for a memory object (and probably doesn't work). This use is
not portable, so let's avoid it.

src/fuzz/fuzz.h
src/portable/portablectl.c
src/test/test-fileio.c
src/test/test-libmount.c

index a7d3a89fe2c52ac0769bbb4a8be35c9a3825c78f..77e0ad98dc3e919d0f736feb7831682c5deecca9 100644 (file)
@@ -14,7 +14,7 @@ static inline FILE* data_to_file(const uint8_t *data, size_t size) {
         if (size == 0)
                 return fopen("/dev/null", "re");
         else
-                return fmemopen_unlocked((char*) data, size, "re");
+                return fmemopen_unlocked((char*) data, size, "r");
 }
 
 /* Check if we are within the specified size range.
index 341e70621fd9bfb8b7eb8bd2a0f89d219aad07e7..dbae8a4d47603da0e72bccf2b85c0c8c0756ef99 100644 (file)
@@ -344,7 +344,7 @@ static int inspect_image(int argc, char *argv[], void *userdata) {
                 _cleanup_free_ char *pretty_portable = NULL, *pretty_os = NULL;
                 _cleanup_fclose_ FILE *f = NULL;
 
-                f = fmemopen_unlocked((void*) data, sz, "re");
+                f = fmemopen_unlocked((void*) data, sz, "r");
                 if (!f)
                         return log_error_errno(errno, "Failed to open /etc/os-release buffer: %m");
 
@@ -400,7 +400,7 @@ static int inspect_image(int argc, char *argv[], void *userdata) {
                                         *id = NULL, *version_id = NULL, *sysext_scope = NULL, *portable_prefixes = NULL;
                                 _cleanup_fclose_ FILE *f = NULL;
 
-                                f = fmemopen_unlocked((void*) data, sz, "re");
+                                f = fmemopen_unlocked((void*) data, sz, "r");
                                 if (!f)
                                         return log_error_errno(errno, "Failed to open extension-release buffer: %m");
 
index 4f084f6162afcc68d0a8ce8bde8851dd6855efd3..ba6dd9ace9d4ed775f2adfb492ca3604f22db7e0 100644 (file)
@@ -677,7 +677,7 @@ TEST(fgetc) {
         _cleanup_fclose_ FILE *f = NULL;
         char c;
 
-        assert_se(f = fmemopen_unlocked((void*) chars, sizeof(chars), "re"));
+        assert_se(f = fmemopen_unlocked((void*) chars, sizeof(chars), "r"));
 
         for (size_t i = 0; i < sizeof(chars); i++) {
                 assert_se(safe_fgetc(f, &c) == 1);
@@ -770,7 +770,7 @@ static void test_read_line_one_file(FILE *f) {
 TEST(read_line1) {
         _cleanup_fclose_ FILE *f = NULL;
 
-        assert_se(f = fmemopen_unlocked((void*) buffer, sizeof(buffer), "re"));
+        assert_se(f = fmemopen_unlocked((void*) buffer, sizeof(buffer), "r"));
         test_read_line_one_file(f);
 }
 
index b3e1a327ab4a4c148cf3099f49e729db9522584e..9ba428e5befbeea99cb0b82cdaf60ac7f7db254f 100644 (file)
@@ -21,7 +21,7 @@ static void test_libmount_unescaping_one(
         _cleanup_(mnt_free_iterp) struct libmnt_iter *iter = NULL;
         _cleanup_fclose_ FILE *f = NULL;
 
-        f = fmemopen((char*) string, strlen(string), "re");
+        f = fmemopen((char*) string, strlen(string), "r");
         assert_se(f);
 
         assert_se(libmount_parse(title, f, &table, &iter) >= 0);