X-Git-Url: https://git.sven.stormbind.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fposix%2Fpsutil.c;h=9beea88f54b095c09db0b33a34985a12d9c4b0d5;hb=refs%2Ftags%2Fdebian%2F2.1-1;hp=847a0609a332f1eff46eebe5515ee76c873b8347;hpb=54ba80f2c210c8003b4ab5c7112ab64063ee8212;p=sven%2Fjattach.git

diff --git a/src/posix/psutil.c b/src/posix/psutil.c
index 847a060..9beea88 100644
--- a/src/posix/psutil.c
+++ b/src/posix/psutil.c
@@ -129,15 +129,18 @@ int get_process_info(int pid, uid_t* uid, gid_t* gid, int* nspid) {
     int nspid_found = 0;
 
     while (getline(&line, &size, status_file) != -1) {
-        if (strncmp(line, "Uid:", 4) == 0) {
+        if (strncmp(line, "Uid:", 4) == 0 && strtok(line + 4, "\t ") != NULL) {
             // Get the effective UID, which is the second value in the line
-            *uid = (uid_t)atoi(strchr(line + 5, '\t'));
-        } else if (strncmp(line, "Gid:", 4) == 0) {
+            *uid = (uid_t)atoi(strtok(NULL, "\t "));
+        } else if (strncmp(line, "Gid:", 4) == 0 && strtok(line + 4, "\t ") != NULL) {
             // Get the effective GID, which is the second value in the line
-            *gid = (gid_t)atoi(strchr(line + 5, '\t'));
+            *gid = (gid_t)atoi(strtok(NULL, "\t "));
         } else if (strncmp(line, "NStgid:", 7) == 0) {
             // PID namespaces can be nested; the last one is the innermost one
-            *nspid = atoi(strrchr(line, '\t'));
+            char* s;
+            for (s = strtok(line + 7, "\t "); s != NULL; s = strtok(NULL, "\t ")) {
+                *nspid = atoi(s);
+            }
             nspid_found = 1;
         }
     }