From 1d817fa41dd931263dcfc97a4edc1246743b5dd5 Mon Sep 17 00:00:00 2001 From: jD91mZM2 <me@krake.one> Date: Mon, 13 Aug 2018 11:45:13 +0200 Subject: [PATCH] Push null after argv --- src/syscall/process.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/syscall/process.rs b/src/syscall/process.rs index 32af87a..5596e8f 100644 --- a/src/syscall/process.rs +++ b/src/syscall/process.rs @@ -675,17 +675,21 @@ fn fexec_noreturn( context.tls = Some(tls); } - // Push end of variables - sp -= mem::size_of::<usize>(); - unsafe { *(sp as *mut usize) = 0; } + let mut arg_size = 0; // Push arguments and variables - let mut arg_size = 0; - for arg in vars.iter().rev().chain(args.iter().rev()) { + for iter in &[&vars, &args] { + // Push null-terminator sp -= mem::size_of::<usize>(); - unsafe { *(sp as *mut usize) = ::USER_ARG_OFFSET + arg_size; } + unsafe { *(sp as *mut usize) = 0; } - arg_size += arg.len() + 1; + // Push content + for arg in iter.iter().rev() { + sp -= mem::size_of::<usize>(); + unsafe { *(sp as *mut usize) = ::USER_ARG_OFFSET + arg_size; } + + arg_size += arg.len() + 1; + } } // Push arguments length -- GitLab