Spherical forums

Sphere Development => Engine Development => Topic started by: Fat Cerberus on May 15, 2015, 01:42:59 pm

Title: Sphere path escapes
Post by: Fat Cerberus on May 15, 2015, 01:42:59 pm
In Sphere, ~/... is a path which is relative to the game directory.  TurboSphere adds #~/... for the system directory.  Are there any other escapes I should know about?  I will add them to minisphere for the 1.1 release. :)
Title: Re: Sphere path escapes
Post by: Flying Jester on May 15, 2015, 03:25:51 pm
I don't know the answers, but there are a couple things that should probably be checked if you want to really be compatible:



I don't strongly escape paths in TurboSphere although I do fully canonize them with respect to the TurboSphere directory for relative paths and the root on Unix and drive path on Windows and the pool on Solaris. The level of canonization is important. Without that, this would fail if there is no `other` directory:

Code: (JavaScript) [Select]

var image_file = new RawFile("../images/raw.tga");


But I also do not sandbox the engine with regards to the FS. Either the user knows the absolute path, or you it's relative and you would have to walk the FS by hand. Will you sandbox the FS?
Title: Re: Sphere path escapes
Post by: Fat Cerberus on May 15, 2015, 03:42:24 pm
Currently it's sandboxed insomuch as absolute paths are rejected (get_asset_path() returns NULL).  Tricks with ../ can bypass it though, as I was too lazy to prevent that.  Of course honestly, I only sandboxed it at all because that's what Sphere does, I suppose it wouldn't hurt to open it up.  Nobody's going to be programming viruses in Sphere. :P

I do canonize paths, yes.  Also ../images/filename will work even if the "other" directory doesn't exist because Allegro's path routines don't care whether the dir exists or not, just that it's a well-formed path.

Edit: no it won't, ignore me, I'm an idiot.  You can't blindly collapse double-dots in paths because one of the components could be a symlink.  So a relative upstream path from a nonexistent directory is indeed broken--UNLESS the semantics of the API in question include a clause to create the directory--for example, OpenLog(), and OpenRawFile() in write mode.
Title: Re: Sphere path escapes
Post by: Fat Cerberus on May 15, 2015, 09:47:39 pm

I don't know the answers, but there are a couple things that should probably be checked if you want to really be compatible


So I did a few tests.

Code: (javascript) [Select]
function game()
{
    var sound = LoadSound('<fill in path>/Munch.wav')
    sound.play(true);
    while (true) FlipScreen();
}