From 6f35028e8464867d19d8551cd1447fc81807143e Mon Sep 17 00:00:00 2001 From: zawwz Date: Fri, 8 Jan 2021 12:02:04 +0100 Subject: [PATCH] fix variable processing broken on debashified process substitution --- include/struc_helper.hpp | 1 + src/debashify.cpp | 16 +++++++++------- src/struc_helper.cpp | 5 +++++ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/include/struc_helper.hpp b/include/struc_helper.hpp index 8d3f4f0..e91f078 100644 --- a/include/struc_helper.hpp +++ b/include/struc_helper.hpp @@ -3,6 +3,7 @@ #include "struc.hpp" +arg* make_arg(std::string const& in); cmd* make_cmd(std::vector const& args); cmd* make_cmd(std::string const& in); condlist* make_condlist(std::string const& in); diff --git a/src/debashify.cpp b/src/debashify.cpp index 2b56379..1e44fe9 100644 --- a/src/debashify.cpp +++ b/src/debashify.cpp @@ -88,7 +88,7 @@ bool debashify_replace_procsub(list* lst) { for(auto ait: t->args->args) { - if(ait->sa[0]->type == _obj::subarg_procsub) + if(ait->sa.size() == 1 && ait->sa[0]->type == _obj::subarg_procsub) { procsub_subarg* st = dynamic_cast(ait->sa[0]); affected_args.push_back( std::make_pair(ait, st->is_output) ); @@ -103,15 +103,15 @@ bool debashify_replace_procsub(list* lst) { has_replaced=true; list* lst_insert = new list; - std::vector mkfifoargs = {"mkfifo"}; + std::string mkfifocmd="mkfifo"; for(uint32_t i=0; iadd( make_condlist( strf("__lxshfifo%u=${TMPDIR-/tmp}/lxshfifo_$(__lxsh_random 10)", i) ) ); - mkfifoargs.push_back( strf("\"$__lxshfifo%u\"", i) ); + mkfifocmd += strf(" \"$__lxshfifo%u\"", i); } // mkfifo "$fifoN" - lst_insert->add( new condlist(make_cmd(mkfifoargs)) ); + lst_insert->add( make_condlist(mkfifocmd) ); for(uint32_t i=0; i "$fifoN" ; rm "$fifoN") & @@ -122,7 +122,7 @@ bool debashify_replace_procsub(list* lst) // deindex list st->sbsh->lst=nullptr; // {PSUB;} > "$__lxshfifoN" - cbr->redirs.push_back( new redirect( affected_args[i].second ? "<" : ">", new arg(strf("\"$__lxshfifo%u\"", i)) ) ); + cbr->redirs.push_back( new redirect( affected_args[i].second ? "<" : ">", make_arg(strf("\"$__lxshfifo%u\"", i)) ) ); // ( {PSUB;} > "$__lxshfifoN" ) psub->lst->add( new condlist(cbr) ); // ( {PSUB;} > "$__lxshfifoN" ; rm "$__lxshfifoN" ) @@ -134,7 +134,9 @@ bool debashify_replace_procsub(list* lst) // replace the arg delete affected_args[i].first->sa[0]; - affected_args[i].first->sa[0] = new string_subarg(strf("\"$__lxshfifo%u\"", i)); + affected_args[i].first->sa[0] = new string_subarg("\""); + affected_args[i].first->sa.push_back( new variable_subarg(strf("__lxshfifo%u", i)) ); + affected_args[i].first->sa.push_back( new string_subarg("\"") ); } lst->insert(li, *lst_insert ); li+= lst_insert->size(); @@ -211,5 +213,5 @@ void debashify(shmain* sh) sh->shebang = "#!/bin/sh"; recurse(r_debashify, sh, &need_random_func); if(need_random_func) - sh->lst->insert(0, new condlist(create_random_func())); + sh->lst->insert(0, new condlist(create_random_func())); } diff --git a/src/struc_helper.cpp b/src/struc_helper.cpp index b03c810..fbb09db 100644 --- a/src/struc_helper.cpp +++ b/src/struc_helper.cpp @@ -5,6 +5,11 @@ // ** FUNCTIONS ** // +arg* make_arg(std::string const& in) +{ + return parse_arg(in.c_str(), in.size(), 0).first; +} + cmd* make_cmd(std::vector const& args) { cmd* ret = new cmd();