* src/main.cpp: Bug fix - nul terminate the result of readlink after checking for failure.

This commit is contained in:
rain1
2016-04-18 18:34:08 +01:00
parent b6a595ae00
commit 30f1072946

View File

@@ -184,9 +184,13 @@ int main(int argc, char **argv) {
if (geteuid() != 0) { if (geteuid() != 0) {
#ifdef __linux__ #ifdef __linux__
char exe_path[PATH_MAX]; char exe_path[PATH_MAX];
unsigned int caps[5] = {0}; ssize_t len;
unsigned int caps[5] = {0,0,0,0,0};
if ((len = readlink("/proc/self/exe", exe_path, PATH_MAX)) == -1)
forceExit(false, "Failed to locate nethogs binary.");
exe_path[len] = '\0';
readlink("/proc/self/exe", exe_path, PATH_MAX);
getxattr(exe_path, "security.capability", (char *)caps, sizeof(caps)); getxattr(exe_path, "security.capability", (char *)caps, sizeof(caps));
if ((((caps[1] >> CAP_NET_ADMIN) & 1) != 1) || (((caps[1] >> CAP_NET_RAW) & 1) != 1)) if ((((caps[1] >> CAP_NET_ADMIN) & 1) != 1) || (((caps[1] >> CAP_NET_RAW) & 1) != 1))