aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2021-10-28 23:38:58 -0400
committerMike Frysinger <vapier@gentoo.org>2021-10-28 23:38:58 -0400
commitc029863b70ca77f59cd181974cfab0fa18c0a265 (patch)
treea0abc3a3b8b2c76b87ec363aaf52c62074719f07 /src
parentlibsandbox: hoist the *at pre-check functions up a level (diff)
downloadsandbox-c029863b70ca77f59cd181974cfab0fa18c0a265.tar.gz
sandbox-c029863b70ca77f59cd181974cfab0fa18c0a265.tar.bz2
sandbox-c029863b70ca77f59cd181974cfab0fa18c0a265.zip
sandbox: avoid repetitive strlen calculations when building cmdline
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Diffstat (limited to 'src')
-rw-r--r--src/sandbox.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/sandbox.c b/src/sandbox.c
index 6cd5f38..7e8a769 100644
--- a/src/sandbox.c
+++ b/src/sandbox.c
@@ -263,21 +263,19 @@ int main(int argc, char **argv)
str_list_add_item_copy(argv_bash, sandbox_info.sandbox_rc, oom_error);
if (argc >= 2) {
int i;
+ size_t cmdlen;
+ char *cmd = NULL;
str_list_add_item_copy(argv_bash, run_str, oom_error);
str_list_add_item_copy(argv_bash, argv[1], oom_error);
+ cmdlen = strlen(argv_bash[4]);
for (i = 2; i < argc; i++) {
- char *tmp_ptr;
-
- tmp_ptr = xrealloc(argv_bash[4],
- (strlen(argv_bash[4]) +
- strlen(argv[i]) + 2) *
- sizeof(char));
- argv_bash[4] = tmp_ptr;
-
- snprintf(argv_bash[4] + strlen(argv_bash[4]),
- strlen(argv[i]) + 2, " %s",
- argv[i]);
+ size_t arglen = strlen(argv[i]);
+ argv_bash[4] = xrealloc(argv_bash[4], cmdlen + arglen + 2);
+ argv_bash[4][cmdlen] = ' ';
+ memcpy(argv_bash[4] + cmdlen + 1, argv[i], arglen);
+ cmdlen += arglen + 1;
+ argv_bash[4][cmdlen] = '\0';
}
}