Skip to content

Fixed possibility to load the same script more than once. - #660

Merged
Y-Less merged 7 commits into
openmultiplayer:masterfrom
dev-karpov0:fix-loading_script_twice
Jun 18, 2023
Merged

Y-Less merged 7 commits into
openmultiplayer:masterfrom
dev-karpov0:fix-loading_script_twice

Conversation

@dev-karpov0

Copy link
Copy Markdown
Contributor

User could load the same script more than once the following ways:

  1. load script with and without extension
loadfs test_script
loadfs test_script.amx
  1. load script by command loadscript with rel. path to script that contains different slashes, e.g.
loadscript filterscripts/test_script
loadscript filterscripts\test_script

Added new function utils::CanonicaliseScriptName() that canonized path to script and adds an extension to the name of the script if it is missing. This ensures that the PawnScript::name_ will always contain the name + extension of script.

@CLAassistant

CLAassistant commented May 20, 2023 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Fix format
Fixed placement of function CanonicaliseScriptName()
@dev-karpov0
dev-karpov0 marked this pull request as draft May 21, 2023 02:02
@dev-karpov0 dev-karpov0 changed the title Fixed possibility to load the same script more than once. [DRAFT] Fixed possibility to load the same script more than once. May 21, 2023
@Y-Less

Y-Less commented May 21, 2023

Copy link
Copy Markdown
Collaborator

You can load scripts twice, and I've seen this exploited to reload a script by loading the second one first, sharing data between them, then closing the original. I don't know if those weird exploits are worth preserving this behaviour for, but it is at least worth discussing. Having said that, I've also seen this exploit done using relative paths like loadfs ..\filterscripts\x vs loadfs x,
and we already fixed that so...

Now that function only adds .amx extension (if needed) and replaces path delimiters (if it present)
@dev-karpov0

Copy link
Copy Markdown
Contributor Author

I've also seen this exploit done using relative paths like loadfs ..\filterscripts\x vs loadfs x, and we already fixed that so...

No, it's not fixed (at least in RC2 release).

I've seen this exploited to reload a script by loading the second one first, sharing data between them, then closing the original

It's quite useful way to save data while restarting scripts, but the way to reload scripts shouldn't be so weird.

I made this fix because I was getting errors when entering commands reloadfs and reloadscript (as if the scripts were not loaded). It was confusing until I figured out what was going on.

My config file looks like this:

"side_scripts": [
    "filterscripts\\script1.amx", 
    "filterscripts\\script2.amx", 
]

Entering reloadfs script1 results an error.
In Windows it's impossible to reload script by reloadfs if you use \\ slash in config, only by reloadscript like that: reloadscript filterscripts\script1.amx. If script name (in config) given with extension you must also specify that ext. in command. Otherwise it results an error.

@Y-Less

Y-Less commented May 21, 2023

Copy link
Copy Markdown
Collaborator

No, it's not fixed (at least in RC2 release).

Oh, well then...

It's quite useful way to save data while restarting scripts, but the way to reload scripts shouldn't be so weird.

In that case I'd agree. Fix this so .amx or not makes no difference and keep the ../ trick. Not reloading scripts because you did or didn't use the extension is just weird as you say, but explicitly bypassing the system by using ../ is a deliberate act we should allow IMHO.

@dev-karpov0
dev-karpov0 marked this pull request as ready for review May 21, 2023 23:23
@dev-karpov0 dev-karpov0 changed the title [DRAFT] Fixed possibility to load the same script more than once. Fixed possibility to load the same script more than once. May 21, 2023
@dev-karpov0

Copy link
Copy Markdown
Contributor Author

The last commit is ready for review.
FIxed /, \ in path and now specifying (or not) the extension when (re)loading script not results an error if script was loaded with (or without) it.

Comment thread Server/Components/Pawn/utils.hpp Resolved
Added an overload to function utils::endWith() to compare the last char.
Comment thread Server/Components/Pawn/utils.hpp Resolved
@dev-karpov0
dev-karpov0 requested a review from AmyrAhmady June 9, 2023 03:19
@Y-Less
Y-Less dismissed AmyrAhmady’s stale review June 18, 2023 14:25

It was resolved, but wasn't marked as such.

@Y-Less
Y-Less merged commit 69097a3 into openmultiplayer:master Jun 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants