From: David Smith Date: Mon, 16 Apr 2018 21:24:36 +0000 (-0500) Subject: Fix a small bug in follow_link(). X-Git-Tag: release-3.3~61 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=7df9f1914b90f65ea3d8c64a8ac6dd0469de416e;p=systemtap.git Fix a small bug in follow_link(). * util.cxx (follow_link): Correctly terminate strings after calling readlink(). --- diff --git a/util.cxx b/util.cxx index 43be61ca0..2e3f4aee2 100644 --- a/util.cxx +++ b/util.cxx @@ -460,7 +460,8 @@ follow_link(const string& name, const string& sysroot) if (linkname) { r = readlink(f, linkname, st.st_size + 1); - linkname[st.st_size] = '\0'; + if (r != -1) + linkname[r] = '\0'; /* * If we have non-empty sysroot and we got link that * points to absolute path name, we need to look at @@ -487,7 +488,8 @@ follow_link(const string& name, const string& sysroot) if (linkname) { r = readlink(f1, linkname, st.st_size + 1); - linkname[st.st_size] = '\0'; + if (r != -1) + linkname[r] = '\0'; } } else