From: Amavect <amavect@gmail.com>
To: 9front@9front.org
Subject: Re: [9front] exec suicide: sys: bad address in syscall
Date: Sun, 8 May 2022 15:10:21 -0500 [thread overview]
Message-ID: <20220508151021.7cc0f0df@spruce.localdomain> (raw)
In-Reply-To: <CAO+DOcqq4RSa_vyhEHBxjGgmJ-ux_B3ShWMN-cy5YquWnaChtw@mail.gmail.com>
On Sun, 8 May 2022 17:38:27 +0000
istvan bak <bdhpfl@gmail.com> wrote:
> term% 6.red 666: suicide: invalid address 0x7fff00000000/1 in sys call
> execl("/bin/rc", "/bin/rc", "-c", cmd, 0);
You have been bitten by varargs.
The 4 bytes of 0x7fff00000000 is 32 bits.
That 0 is a 32-bit integer.
The 0 is not being converted due to varargs.
Casting to (char*) or (void*) fixes your issue.
See the warning when compiling this:
print("%p", 0);
warning: red.c:17 format mismatch p INT, arg 2
This is a problem in every C implementation.
Varargs suck.
For fun, the disassembly:
without casting (MOVL moves a 32 bit value):
rc+0x42 0x000000000020006a MOVL $0x0,0x20(SP)
rc+0x4a 0x0000000000200072 CALL execl(SB)
with casting (MOVQ moves a 64 bit value):
rc+0x42 0x000000000020006a MOVQ $0x0,0x20(SP)
rc+0x4b 0x0000000000200073 CALL execl(SB)
Note that run2() doesn't cast, either.
You got lucky that the higher 32 bits are zero.
Thanks,
Amavect
next prev parent reply other threads:[~2022-05-08 20:14 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-08 17:38 istvan bak
2022-05-08 19:53 ` ori
2022-05-08 20:10 ` Amavect [this message]
2022-05-08 21:45 ` istvan bak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220508151021.7cc0f0df@spruce.localdomain \
--to=amavect@gmail.com \
--cc=9front@9front.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).