Skip to content

rz-gg: sflib incorrect argument constraints on linux i386 #3476

@giladreti

Description

@giladreti

note: this issue cannot be reproduced before #3475 is merged as rz-gg just doesn't work without it.

it seems like shellforge had a regression in i386 binary generation when calling syscalls.
the problem was introduced in rizin in PR #2428 which updated the autogenerated sflib. as can be seen, the argument constaints of the syscall wrappers changed from r (general purpose register) to g (which allows memory locations too). this can cause problems as the syscall functions save ebx on the stack which moves esp without the compiler knowledege which can make it reference stack saved arguments wrongly.
i opened a PR to shellforge4 at whatsbcn/shellforge4#7. when it is fixed, i think it should suffice to regenerate sflib and update rizin's sflib.

Expected behavior

when compiling

int log(char *s, int l) {
  write(2, s, l);
}

int main() {
  log("hello", sizeof("hello"));
  log(" ", sizeof(" "));
  log("world!", sizeof("world!"));
  exit(0);
}

via rz-gg -b 32 -a x86 -F -O test.c and running ./test hello world! should be printed

Actual behavior

hello is printed.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions