Changeset - r24276:90840fb148a2
[Not reviewed]
master
0 1 0
glx22 - 4 years ago 2020-06-22 12:21:11
glx22@users.noreply.github.com
Fix #8230: Resolve ".." when opening files in .tar (#8231)
1 file changed with 23 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/fileio.cpp
Show inline comments
 
@@ -25,6 +25,7 @@
 
#endif
 
#include <sys/stat.h>
 
#include <algorithm>
 
#include <sstream>
 

	
 
#ifdef WITH_XDG_BASEDIR
 
#include <basedir.h>
 
@@ -481,6 +482,28 @@ FILE *FioFOpenFile(const char *filename,
 
		strecpy(resolved_name, filename, lastof(resolved_name));
 
		strtolower(resolved_name);
 

	
 
		/* Resolve ".." */
 
		std::istringstream ss(resolved_name);
 
		std::vector<std::string> tokens;
 
		std::string token;
 
		while (std::getline(ss, token, PATHSEPCHAR)) {
 
			if (token == "..") {
 
				if (tokens.size() < 2) return nullptr;
 
				tokens.pop_back();
 
			} else {
 
				tokens.push_back(token);
 
			}
 
		}
 
		resolved_name[0] = '\0';
 
		bool first = true;
 
		for (const std::string &token : tokens) {
 
			if (!first) {
 
				strecat(resolved_name, PATHSEP, lastof(resolved_name));
 
			}
 
			strecat(resolved_name, token.c_str(), lastof(resolved_name));
 
			first = false;
 
		}
 

	
 
		size_t resolved_len = strlen(resolved_name);
 

	
 
		/* Resolve ONE directory link */
0 comments (0 inline, 0 general)