Community discussions

MikroTik App
军刀
刚刚加入了
Topic Author
Posts: 9
加入: Wed May 24, 2023 3:43 pm

频繁的空变量在脚本中被证明be Bug ?

Fri Jul 14, 2023 7:50 pm

Every occurrence of an empty variable is on the third line.
Screenshot 2023-07-15 004554.png

Script Code:
{
:local func do={ :put "txt $domainName" }

[$func domainName=123]
[$func domainName=223]
}
You do not have the required permissions to view the files attached to this post.
Top
用户头像
rextended
Forum Guru
Forum Guru
Posts: 11495
加入: Tue Feb 25, 2014 12:49 pm
Location:Italy
Contact:

Re: [BUGOS] Frequent empty variables in scripts turned out to be Bug ?

Fri Jul 14, 2023 8:23 pm

Code:Select all
{ :local func do={ :return "txt $domainName" } :put [$func domainName=123] :put [$func domainName=223] :put [$func domainName=323] :put [$func domainName=423] }

Code:Select all
{ :local func ":put \"txt \$domainName\"" :local domainName 123 [:parse ":local domainName $domainName ; $func"] :local domainName 223 [:parse ":local domainName $domainName ; $func"] :local domainName 323 [:parse ":local domainName $domainName ; $func"] :local domainName 423 [:parse ":local domainName $domainName ; $func"] }

Code:Select all
{ :local func do={ :return {"domainName"="txt $domainName";"another"="text string"} } :put ([$func domainName="123"]->"domainName") :put ([$func domainName="223"]->"domainName") :put ([$func domainName="666"]->"another") }
Last edited byrextendedon Fri Jul 14, 2023 8:37 pm, edited 2 times in total.
Top
用户头像
Amm0
Forum Guru
Forum Guru
Posts: 2377
加入: Sun May 01, 2016 7:12 pm
Location:California

Re: [BUGOS] Frequent empty variables in scripts turned out to be Bug ?

Fri Jul 14, 2023 8:32 pm

The "subshell" []backets aren't strictly needed in the code block. So this does what you'd expect:
{
:local func do={ :put "txt $domainName"}
$func domainName=123
$func domainName=223
}

or even this works – it's the last one can't be subshell I think...
{
:local func do={ :put "txt $domainName" }
[$func domainName=123]
$func domainName=223
}

In theory, the [$func domainName=223] should be harmless ... but the [] does return a value of the inner command, which in the case of a :put, whose return is string. Somehow the [] subshell is calling the contained function again when exiting the block. That doesn't seem right, but you don't need the [] subshell operators either.
Top
用户头像
rextended
Forum Guru
Forum Guru
Posts: 11495
加入: Tue Feb 25, 2014 12:49 pm
Location:Italy
Contact:

Re: [BUGOS] Frequent empty variables in scripts turned out to be Bug ?

Fri Jul 14, 2023 8:39 pm

I'm updating my post with more examples and final description, you anticipated me;)
Top
kcarhc
频繁的活力itor
频繁的活力itor
Posts: 57
加入: Thu Feb 01, 2018 9:54 am

Re: [BUGOS] Frequent empty variables in scripts turned out to be Bug ?

Sat Jul 15, 2023 9:35 am

There is no need to discuss whether [] is necessary.
Even for a function without a return value, adding [] is acceptable.
It is similar to a regular function where the return value is either 0 or empty.

The actual problem is that no matter how many lines are executed,
after the second execution, there will be a phantom execution with empty parameters.
This is a bug in the RouterOS script interpreter itself.
Since it has been reproduced, MikroTik can fix it.

I believe this issue will be resolved in version 7.10.3/7.11 or possibly in future versions like 7.12.
Otherwise, it could be exploited by someone as a buffer overflow to execute attack code.
Top
用户头像
rextended
Forum Guru
Forum Guru
Posts: 11495
加入: Tue Feb 25, 2014 12:49 pm
Location:Italy
Contact:

Re: [BUGOS] Frequent empty variables in scripts turned out to be Bug ?

Sat Jul 15, 2023 6:48 pm

Otherwise, it could be exploited by someone as a buffer overflow to execute attack code.
Surely if someone has access to write new scripts in the RouterBOARD they will worry about causing buffer overflows on the machine they already have under control...
Top
用户头像
Amm0
Forum Guru
Forum Guru
Posts: 2377
加入: Sun May 01, 2016 7:12 pm
Location:California

Re: [BUGOS] Frequent empty variables in scripts turned out to be Bug ?

Sat Jul 15, 2023 7:53 pm

Glad MT fixing it. Not sure this a new issue however – pretty sureI 've run into this issue myself at some point (using [] for a fn call inside a block as the only line). But I still think [] are an unnecessary if one is pandantic – but was not an argument to not fix it;)Now totally not sure the security argument here... it may not be correct behavior, but it's not like some code gets access to memory/etc as a result of it.
Top
用户头像
Amm0
Forum Guru
Forum Guru
Posts: 2377
加入: Sun May 01, 2016 7:12 pm
Location:California

Re: [BUGOS] Frequent empty variables in scripts turned out to be Bug ?

Sat Jul 15, 2023 8:01 pm

Again, not to argue it's not a bug... But also I just think it's good practice to always return a value (even if it's [:nothing]) from a function. So @rextended's example just seems "safer" approach.
Code:Select all
{ :local func do={ :return "txt $domainName" } :put [$func domainName=123] :put [$func domainName=223] :put [$func domainName=323] :put [$func domainName=423] }
Top
用户头像
rextended
Forum Guru
Forum Guru
Posts: 11495
加入: Tue Feb 25, 2014 12:49 pm
Location:Italy
Contact:

Re: [BUGOS] Frequent empty variables in scripts turned out to be Bug ?

Sun Jul 16, 2023 12:48 am

( and if is needed, on the last example is returned one array of return values... )
Top
Sertik
Member
Member
Posts: 309
加入: Fri Sep 25, 2020 3:30 pm

Re: Frequent empty variables in scripts turned out to be Bug ?

Mon Jul 17, 2023 3:04 pm

No, they won't fix it. We reported a long time ago that when a function is executed twice in a subshell, it is executed three times. Woz and now there. Mikrotik doesn't know how to fix the error.
Code:Select all
[$myFunc] [$myFunc]
Yes, I agree with Amm0, there is no "third time error" without a shell.
Code:Select all
$myFunc $myFunc
This is the name of this case I liked:[$BUGOS] :D
Top
kcarhc
频繁的活力itor
频繁的活力itor
Posts: 57
加入: Thu Feb 01, 2018 9:54 am

Re: Frequent empty variables in scripts turned out to be Bug ?

Mon Jul 31, 2023 12:35 pm

already confirm in SUP-122073, will be fix soon.
Top

Who is online

Users browsing this forum: No registered users and 5 guests