Opened 16 years ago

Closed 16 years ago

Last modified 6 years ago

#8754 closed patch (outdated)

MAIN.CPP Patch for ~ on Linux/Unix systems

Reported by: SF/d_skywalk Owned by: fingolfin
Priority: normal Component: Port: Linux
Version: Keywords:
Cc: Game:


I submit a simple patch for work "~" on paths in scummvmrc file:

Ex: [atlantis] description=Test for scummvm team path=~/dirgames/game platform=pc language=es

CODE (main.cpp) _______________

static int runGame(const Plugin *plugin, OSystem &system, const Common::String &edebuglevels) { Common::String gameDataPath(ConfMan.get("path"));

+ #if defined(UNIX) + if(gameDataPath.hasPrefix("~/")){ + gameDataPath.deleteChar(0); + gameDataPath = getenv("HOME") + gameDataPath; + } + #endif

if (gameDataPath.empty()) { } else if (gameDataPath.lastChar() != '/' ____________________________

Cu guys!

Ticket imported from: #1846545. Ticket imported from: patches/859.

Change History (7)

comment:1 by fingolfin, 16 years ago

Moving to patch tracker.

This patch would make us vulnerable to environment spoofing attacks. At the very least, the length of getenv("HOME") should be restricted. *If* we decide we want to implement support for ~, that is ;)

comment:2 by SF/d_skywalk, 16 years ago

You are right! :)

Better patch implementation:

CODE (main.cpp - function runGame(const Plugin *plugin...) _____________________________

if (gameDataPath.empty()) { } else + #if defined(UNIX) && !defined(GP2X) // GP2X is Linux has no Home dir. + if(gameDataPath.hasPrefix("~/")) { + const char *home = getenv("HOME"); + if (home != NULL && strlen(home) < MAXPATHLEN) { + gameDataPath.deleteChar(0); + gameDataPath = home + gameDataPath; + } + } else + #endif if (gameDataPath.lastChar() != '/' #if defined(__MORPHOS__) || defined(__amigaos4__) _____________________________________________

Thanks for your great work! :) David

comment:3 by fingolfin, 16 years ago

Better. However, even better is to simply modify posix-fs.cpp to always expand "~/". That way, one can use "~" in almost all kinds of paths, and the change is cleanly separated, too.

So I commited this feature just now. Let me know if it causes you any troubles.

comment:4 by fingolfin, 16 years ago

Owner: set to fingolfin
Resolution: outdated
Status: newclosed

comment:5 by SF/d_skywalk, 16 years ago

Hi again fingolfin :)

I see the patch: > Expand ~/ to the HOME env var (see also patch #1846545) > ------------------------------------------------------------------------ > r29796 | thebluegr | 2007-12-09 13:43:08 -0200 (Sun, 09 Dec 2007) | 1 line

Wow my first scummvm patch :D

I dont think so, the patch converts only (when the game init) the original path in config (~/ to /home/$USER/), when the change is made, scummvm thinks that the original path in config is "/home/$USER...". So only one time to compare and only one convert :) But if you add a similar patch to posix backend, every call to his DIR function need compare and convert the "~" character.

Cu and sorry for my terrible english ;)

comment:6 by fingolfin, 16 years ago

We have a misunderstanding here :). Your patch was *not* added to SVN; and you are also quoting the commit logs incorrectly. Rather, it was me who commited rev. 29797 with the comment "Expand ~/ to the HOME env var (see also patch #1846545)". See <>

The patch I commited works differently than your patch: It modifies the POSIX backend to add support for "~/". This way, whenever any path in the config file is parsed, the "~/" will get expanded (assuming the code reading from the config file is written properly and uses FilesytemNodes, that is). In particular, with my changes, also the "extra" path or the "themepath" can use "~/".

comment:7 by digitall, 6 years ago

Component: Port: Linux
Note: See TracTickets for help on using tickets.