mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-07-17 16:47:50 +00:00
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 <avagin@google.com> Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
This commit is contained in:
parent
838a59087d
commit
5c994447a0
1 changed files with 6 additions and 3 deletions
|
|
@ -2,6 +2,7 @@
|
|||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/mount.h>
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue