flat assembler
Message board for the users of flat assembler.
Index
> Linux > Help:Label declaration order, how is this impacting my code? |
Author |
|
Tomasz Grysztar 12 Nov 2019, 11:41
When you read directory entry, you specify buffer size 1024, but your "dirent64" macro reserves only 19 bytes. Thus you end up overwriting data that follows - in this case your "texto" string. When you swap the definitions, you no longer have anything of value after "dirent" to get overwritten (but there is still some memory available there, because segment size is aligned to 4096 bytes).
Therefore, first and foremost: when you specify a size of a buffer (1024 in this case) always make sure that you actually have that much free space at the address you provide. Otherwise you're likely to get a buffer overflow and overwrite something important. I would suggest using an additional constant to ensure that you do not indicate more space than you actually reserved: Code: DIRENT_BUFSIZE = 1024 Code: mov rdi, rax lea rsi, [dirent] mov rdx, DIRENT_BUFSIZE mov rax, SYS_GETDENTS64 syscall Code: segment readable writable dirent dirent64 rb DIRENT_BUFSIZE - ($-dirent) In addition to that, consider putting your immutable data (like the "texto" string) in a separate segment for read-only data (give it no "writable" attribute). |
|||
12 Nov 2019, 11:41 |
|
guitmz 12 Nov 2019, 11:55
@Tomasz yeah. That was something inline with what I was guessing, thank you so much! Learned something today.
As for the writable segment, you are also right, thanks for reminding me, I just added the string there to quickly test. Best regards, thanks for the awesome work! |
|||
12 Nov 2019, 11:55 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.