]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: terminate readlink result in resapwn 1729/head
authorSage Weil <sage@inktank.com>
Sat, 26 Apr 2014 02:46:24 +0000 (19:46 -0700)
committerSage Weil <sage@inktank.com>
Sat, 26 Apr 2014 02:46:24 +0000 (19:46 -0700)
readlink(2) does not null terminate the buffer; we need to do that.

Fixes: #7966
Signed-off-by: Sage Weil <sage@inktank.com>
src/mds/MDS.cc

index 1d9015a22eb613635030771d552a43c5701419a3..4509cea214e8b857df71cdaa1e1aac725965e882 100644 (file)
@@ -1702,8 +1702,9 @@ void MDS::respawn()
   /* Determine the path to our executable, try to read
    * linux-specific /proc/ path first */
   char exe_path[PATH_MAX];
-  ssize_t exe_path_bytes = readlink("/proc/self/exe", exe_path, sizeof(exe_path));
-  if (exe_path_bytes == -1) {
+  ssize_t exe_path_bytes = readlink("/proc/self/exe", exe_path,
+                                   sizeof(exe_path) - 1);
+  if (exe_path_bytes < 0) {
     /* Print CWD for the user's interest */
     char buf[PATH_MAX];
     char *cwd = getcwd(buf, sizeof(buf));
@@ -1712,6 +1713,8 @@ void MDS::respawn()
 
     /* Fall back to a best-effort: just running in our CWD */
     strncpy(exe_path, orig_argv[0], sizeof(exe_path) - 1);
+  } else {
+    exe_path[exe_path_bytes] = '\0';
   }
 
   dout(1) << " exe_path " << exe_path << dendl;