From 5c994447a0063cf383f427b8bb5042624ff83d4e Mon Sep 17 00:00:00 2001 From: Pavel Tikhomirov Date: Tue, 3 Feb 2026 20:44:30 +0100 Subject: [PATCH] zdtm/static/binfmt_misc: make the random generation actually random Before that patch we always had exactly the same magic and extentsion patterns generated. While on it let's fix the data restrictions: - The length of extension and magic should be non-zero. - Let's explicitly wrap extension characters with 256. Fixes: #2886 Co-developed-by: Andrei Vagin Signed-off-by: Pavel Tikhomirov --- test/zdtm/static/binfmt_misc.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test/zdtm/static/binfmt_misc.c b/test/zdtm/static/binfmt_misc.c index 036eb9fe9..4863659c5 100644 --- a/test/zdtm/static/binfmt_misc.c +++ b/test/zdtm/static/binfmt_misc.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -30,7 +31,7 @@ void create_magic_pattern(char *buf, const char *name) { int i, magic, mask, offset; - magic = rand() % (MAX_MAGIC + 1); + magic = rand() % MAX_MAGIC + 1; mask = (rand() % 2) ? magic : 0; offset = MAX_MAGIC_OFFSET - magic; offset = rand() % (offset + 1); @@ -52,11 +53,11 @@ void create_extension_pattern(char *buf, const char *name) { int i, extension; - extension = rand() % (MAX_EXTENSION + 1); + extension = rand() % MAX_EXTENSION + 1; buf += sprintf(buf, ":%s:E::", name); for (i = 0; i < extension; i++) { - int c = rand(); + int c = rand() % 256; if (c == '\0' || c == ':' || c == '\n' || c == '/') c = '1'; @@ -102,6 +103,8 @@ int main(int argc, char **argv) char *dump[2]; int i, fd, len; + srand(time(NULL)); + test_init(argc, argv); snprintf(NAME[0], PATH_MAX, "%s_magic", filename);