]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
mfail: do not count allocations for no file when checked
authorJakub Zelenka <jakub.zelenka@openssl.foundation>
Mon, 1 Jun 2026 21:27:55 +0000 (23:27 +0200)
committerTomas Mraz <tomas@openssl.foundation>
Thu, 11 Jun 2026 15:59:53 +0000 (17:59 +0200)
This skips some debug and error allocations that cannot be handled

Reviewed-by: Norbert Pocs <norbertp@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.foundation>
MergeDate: Thu Jun 11 16:00:14 2026
(Merged from https://github.com/openssl/openssl/pull/31356)

test/mfail/mfail.c
test/mfail/mfail.h
test/testutil/driver.c

index 034d9881dac06841d51bfe235f4f8b7cd5995494..254a6a965f40fc1cc63db312ff178430b7181db9 100644 (file)
@@ -54,6 +54,7 @@ static struct {
     int triggered;
     int counting;
     int slow_skipped;
+    int no_check;
 } mf;
 
 static int env_is_true(const char *name)
@@ -92,12 +93,15 @@ static void mfail_print_bt(void)
 #endif
 }
 
-static int should_fail(void)
+static int should_fail(const char *file)
 {
     int idx;
 
     if (!mf.counting)
         return 0;
+    /* skip if checking errors and file is not set (debug and error parts) */
+    if (!mf.no_check && file == NULL)
+        return 0;
 
     idx = mf.alloc_count++;
 
@@ -116,7 +120,7 @@ static void *mf_malloc(size_t num, const char *file, int line)
 {
     if (num == 0)
         return NULL;
-    if (should_fail())
+    if (should_fail(file))
         return NULL;
     return malloc(num);
 }
@@ -129,7 +133,7 @@ static void *mf_realloc(void *addr, size_t num, const char *file, int line)
         free(addr);
         return NULL;
     }
-    if (should_fail())
+    if (should_fail(file))
         return NULL;
     return realloc(addr, num);
 }
@@ -216,6 +220,7 @@ void mfail_init(int seq, int flags)
     mf.triggered = 0;
     mf.counting = 0;
     mf.slow_skipped = 0;
+    mf.no_check = flags & MFAIL_FLAG_NO_CHECK;
 
     if (mf.single_point >= 0) {
         mf.mode = MFAIL_MODE_SINGLE;
index 35888423f8cf7f9aee27827e37386434fb1e2248..6c16e4fe656a4567c4183cb016866de4f1fea0ce 100644 (file)
@@ -12,6 +12,7 @@
 
 /* Flags for mfail_init(). */
 #define MFAIL_FLAG_COUNT (1 << 0)
+#define MFAIL_FLAG_NO_CHECK (1 << 1)
 
 /* Modes */
 #define MFAIL_MODE_EXHAUSTIVE 0
index a3fdc59cc0893a9ad1005373bf2e0ebb967d5d13..86eacd40087a2d5e7817e69e78f78a6eb524a6ac 100644 (file)
@@ -330,7 +330,7 @@ static int mfail_run_test(const TEST_INFO *t, int idx)
     test_flush_stdout();
     test_flush_tapout();
 
-    mfail_init(0, 0);
+    mfail_init(0, no_check ? MFAIL_FLAG_NO_CHECK : 0);
 
     while (mfail_has_next()) {
         int phase = mfail_get_phase();