From 9d6e0319f74dcd284a9fbcf0cda1dedfcfc2e8c8 Mon Sep 17 00:00:00 2001 From: Balazs Gerofi Date: Sat, 14 Oct 2017 09:17:09 +0900 Subject: [PATCH] atobytes(): restore postfix before return --- executer/user/mcexec.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/executer/user/mcexec.c b/executer/user/mcexec.c index 81a73dfc..2f5bc1d7 100644 --- a/executer/user/mcexec.c +++ b/executer/user/mcexec.c @@ -1674,6 +1674,8 @@ static void destroy_local_environ(char **local_env) unsigned long atobytes(char *string) { unsigned long mult = 1; + unsigned long ret; + char orig_postfix = 0; char *postfix; errno = ERANGE; @@ -1685,19 +1687,26 @@ unsigned long atobytes(char *string) if (*postfix == 'k' || *postfix == 'K') { mult = 1024; + orig_postfix = *postfix; *postfix = 0; } else if (*postfix == 'm' || *postfix == 'M') { mult = 1024 * 1024; + orig_postfix = *postfix; *postfix = 0; } else if (*postfix == 'g' || *postfix == 'G') { mult = 1024 * 1024 * 1024; + orig_postfix = *postfix; *postfix = 0; } + ret = atol(string) * mult; + if (orig_postfix) + *postfix = orig_postfix; + errno = 0; - return atol(string) * mult; + return ret; } static struct option mcexec_options[] = {