]> sourceware.org Git - systemtap.git/commitdiff
Fix a small bug in follow_link().
authorDavid Smith <dsmith@redhat.com>
Mon, 16 Apr 2018 21:24:36 +0000 (16:24 -0500)
committerDavid Smith <dsmith@redhat.com>
Mon, 16 Apr 2018 21:24:36 +0000 (16:24 -0500)
* util.cxx (follow_link): Correctly terminate strings after calling
  readlink().

util.cxx

index 43be61ca0385349920c2f37c7aa8d1187a553f5c..2e3f4aee2af56f1a3fc8fb0ab74641a85f6947be 100644 (file)
--- 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
This page took 0.028533 seconds and 5 git commands to generate.