Skip to content

Conversation

@debadree25
Copy link
Contributor

Attempted to fix the issue of the same pointer possibly causing the same random path to be returned by adding a static variable to keep count, I am unsure how I could add a test for this 😅

Fixes: #18591


__clock_gettime(CLOCK_REALTIME, &ts);
r = ts.tv_nsec*65537 ^ (uintptr_t)&ts / 16 + (uintptr_t)template;
r = ts.tv_nsec*65537 ^ (uintptr_t)&ts / 16 + (uintptr_t)template + seed++;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you mark with /* XXX EMSCRIPTEN ... */ and maybe try to keep the changes isolated from the original code. How about:

/* XXX EMSCRIPTEN: avoid repeating the same result when __clock_gettime does not change between calls. */
static unsigned int seed = 0;
r += seed++;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

understood, updating it

Copy link
Collaborator

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm % comment

Copy link
Collaborator

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you give a better title to this PR. Perhaps "Avoid repeating the same result in __randname"?

@debadree25 debadree25 changed the title fix: add a static count to increase randomness fix: avoid repeating same result in __randname on passing same template pointer Mar 7, 2023
@debadree25
Copy link
Contributor Author

update the code and title, does it look ok?


/* XXX EMSCRIPTEN: avoid repeating the same result when __clock_gettime does not change between calls. */
static unsigned int seed = 0;
r += seed++;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is seed the right name for this? How about increment or counter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated, counter looks good

@sbc100 sbc100 enabled auto-merge (squash) March 7, 2023 17:41
@sbc100 sbc100 merged commit 2acba41 into emscripten-core:main Mar 7, 2023
impact-maker pushed a commit to impact-maker/emscripten that referenced this pull request Mar 17, 2023
impact-maker pushed a commit to impact-maker/emscripten that referenced this pull request Mar 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Passing the same pointer to __randname twice before the clock ticks generates the same random path

2 participants