flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > 2 small libc version bugs

Author
Thread Post new topic Reply to topic
epinull



Joined: 03 Aug 2011
Posts: 2
epinull 03 Aug 2011, 03:52
Greetings! I'm new here (first post) and I only recently started using fasm. Loving it so far! Smile

I've been using the libc version of fasm and noticed a few small bugs:
1. Fasm doesn't return the correct exit code.
2. When using the -s option, fasm exits with an 'error: write failed' message.

Here's two patches that fix the above mentioned bugs (Apply with: patch -p1):
Edit: Oops! I forgot the mention that these patches are for version 1.69.32.
Exit code patch:
Code:
--- a/source/libc/system.inc
+++ b/source/libc/system.inc
@@ -45,7 +45,8 @@ exit_program:
  movzx   eax,al
      push    eax
         ccall   free,[additional_memory]
-   ccall   exit
+       pop     eax
+        ccall   exit,eax
    mov     esp,[stack_frame]
   pop     ebp
         ret
    


-s option patch:
Code:
--- a/source/libc/system.inc
+++ b/source/libc/system.inc
@@ -120,9 +120,9 @@ read:
        stc
         ret
 write:
- push    ebx ecx edx esi edi
+        push    ebx ecx edx esi edi ebp
     ccall   fwrite,edx,1,ecx,ebx
-       pop     edi esi edx ecx ebx
+        pop     ebp edi esi edx ecx ebx
     cmp     eax,ecx
     jne     file_error
  clc
    
Post 03 Aug 2011, 03:52
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20337
Location: In your JS exploiting you and your system
revolution 03 Aug 2011, 04:56
epinull wrote:
1. Fasm doesn't return the correct exit code.
...
Exit code patch:
Code:
--- a/source/libc/system.inc
+++ b/source/libc/system.inc
@@ -45,7 +45,8 @@ exit_program:
   movzx   eax,al
      push    eax
         ccall   free,[additional_memory]
-   ccall   exit
+       pop     eax
+        ccall   exit,eax
    mov     esp,[stack_frame]
   pop     ebp
         ret    
I don't understand how this helps. The exit code is still passed as the first parameter on the stack in both versions. Question
Post 03 Aug 2011, 04:56
View user's profile Send private message Visit poster's website Reply with quote
epinull



Joined: 03 Aug 2011
Posts: 2
epinull 03 Aug 2011, 07:10
You're right except that the ccall macro has the line: and esp,-1 which seems to missalign the stack before exit is called. At least I think that's what's happening. I'm fairly new to assembly, so I might be wrong...
Post 03 Aug 2011, 07:10
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20337
Location: In your JS exploiting you and your system
revolution 03 Aug 2011, 07:28
Oh I see. Yeah, the ccall macro used is not the same as the usual one. Indeed the stack alignment code can cause the return value to be positioned further up the stack.
Post 03 Aug 2011, 07:28
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.