mirror of https://github.com/kiwix/libkiwix.git
+ Avoid buffer overflow on linux
This commit is contained in:
parent
f69edcf9c0
commit
e885cc342a
|
@ -206,18 +206,22 @@ bool copyFile(const string &sourcePath, const string &destPath) {
|
||||||
|
|
||||||
string getExecutablePath() {
|
string getExecutablePath() {
|
||||||
char binRootPath[PATH_MAX];
|
char binRootPath[PATH_MAX];
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
GetModuleFileName( NULL, binRootPath, PATH_MAX);
|
GetModuleFileName( NULL, binRootPath, PATH_MAX);
|
||||||
|
return std::string(binRootPath);
|
||||||
#elif __APPLE__
|
#elif __APPLE__
|
||||||
uint32_t max = (uint32_t)PATH_MAX;
|
uint32_t max = (uint32_t)PATH_MAX;
|
||||||
_NSGetExecutablePath(binRootPath, &max);
|
_NSGetExecutablePath(binRootPath, &max);
|
||||||
|
return std::string(binRootPath);
|
||||||
#else
|
#else
|
||||||
if (readlink("/proc/self/exe", binRootPath, PATH_MAX) == -1) {
|
ssize_t size = readlink("/proc/self/exe", binRootPath, PATH_MAX);
|
||||||
};
|
if (size != -1) {
|
||||||
|
return std::string(binRootPath, size);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return std::string(binRootPath);
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
bool writeTextFile(const string &path, const string &content) {
|
bool writeTextFile(const string &path, const string &content) {
|
||||||
|
|
Loading…
Reference in New Issue