Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed a problem that always crashes when executing ft_strrchr test code. #146

Merged
merged 2 commits into from
Feb 21, 2023

Conversation

keit0728
Copy link
Contributor

Testing ft_strrchr always crushes with test_ft_strrchr_electric_memory.

ft_strrchr:    [OK] [OK] [OK] [OK] [OK] [OK] [CRASH] [OK] 
[crash]: your strrchr crash because it read too many bytes or attempt to write on s !
Test code:
	char *src = electric_alloc(10);

	__builtin___strcpy_chk (src, "123456789", __builtin_object_size (src, 2 > 1 ? 1 : 0));
	ft_strrchr(src, 'a');
	src = electric_alloc_rev(10);
	__builtin___strcpy_chk (src, "123456789", __builtin_object_size (src, 2 > 1 ? 1 : 0));
	ft_strrchr(src, 'a');
	exit(TEST_SUCCESS);

Upon investigation, I found that it was due to mprotect(ptr, 4096, PROT_NONE); in the electric_alloc_rev function.
I measured the page size on my Macbook pro m1 with the following code and it was 16384.

long page_size = sysconf(_SC_PAGESIZE);

So it should be mprotect(ptr, 16384, PROT_NONE);.
After modifying the code to allocate memory space based on page size, this problem no longer occurs.

@keit0728 keit0728 changed the title Fixed a problem where ft_strrchr test code always crashes. Fixed a problem that always crashes when executing ft_strrchr test code. Jan 18, 2023
@alelievr alelievr merged commit c241ebb into alelievr:master Feb 21, 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.

2 participants