summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 5016bf2)
raw | patch | inline | side by side (parent: 5016bf2)
author | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Wed, 21 Jun 2023 16:46:00 +0000 (19:46 +0300) | ||
committer | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Wed, 21 Jun 2023 16:46:00 +0000 (19:46 +0300) |
src/engine/e_res.pas | patch | blob | history | |
src/game/g_game.pas | patch | blob | history |
diff --git a/src/engine/e_res.pas b/src/engine/e_res.pas
index 69adb6e6eb5faa6b5e4fd98c0d919b270cb50501..81f4638beec76d44a80cb8e85987e6926ffeb9ac 100644 (file)
--- a/src/engine/e_res.pas
+++ b/src/engine/e_res.pas
result := Copy(path, 1, i-1) // exclude the trailing separator
end;
- function HasRelativeDirs (name: AnsiString): Boolean;
- var i: Integer; ch: Char;
+ function IsRelativePath (name: AnsiString): Boolean;
begin
- i := 1;
- result := false;
- while (result = false) and (name[i] <> #0) do
- begin
- ch := name[i];
- if (ch = '/') or (ch = '\') then
- begin
- Inc(i);
- if name[i] = '.' then
- begin
- Inc(i);
- if name[i] = '.' then
- begin
- Inc(i);
- ch := name[i];
- result := (ch = #0) or (ch = '/') or (ch = '\')
- end
- end
- end
- else
- begin
- Inc(i)
- end
- end
+ result := (copy(name, 1, 3) = '../') or (pos('/../', name) <> 0) or (copy(name, Length(name) - 2) = '/..') or
+ (copy(name, 1, 3) = '..\') or (pos('\..\', name) <> 0) or (copy(name, Length(name) - 2) = '\..') or
+ (name = '..');
end;
- function HasAbsoluteDirs (name: AnsiString): Boolean;
+ function IsAbsolutePath (name: AnsiString): Boolean;
begin
- result := (name = '') or (name[1] = '/') or (name[1] = '\')
+ result := ExpandFileName(name) = name;
end;
function e_IsValidResourceName (name: AnsiString): Boolean;
begin
- result := (HasAbsoluteDirs(name) = false) and (HasRelativeDirs(name) = false)
+ result := (IsAbsolutePath(name) = false) and (IsRelativePath(name) = false)
end;
function SpawnStream (dirs: SSArray; name: AnsiString; p: SpawnProc; createNewDir: Boolean): TStream;
diff --git a/src/game/g_game.pas b/src/game/g_game.pas
index 7510eca123454caf27ae768b3ac2c9336e7d226d..29668f59753441a102be2a84c092bf300417c2a7 100644 (file)
--- a/src/game/g_game.pas
+++ b/src/game/g_game.pas
g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
end
end
+ else if not e_IsValidResourceName(P[1]) then
+ begin
+ g_Console_Add('wad name must not be absolute or relative');
+ end
else
begin
if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
end;
end
+ else if not e_IsValidResourceName(P[1]) then
+ begin
+ g_Console_Add('wad name must not be absolute or relative');
+ end
else
begin
nm := False;