about summary refs log tree commit diff
path: root/src/libutil
diff options
context:
space:
mode:
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/util.cc6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index dcdb438e03b2..879f9fb5fddd 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -193,8 +193,12 @@ Path readLink(const Path & path)
     if (!S_ISLNK(st.st_mode))
         throw Error(format("‘%1%’ is not a symlink") % path);
     char buf[st.st_size];
-    if (readlink(path.c_str(), buf, st.st_size) != st.st_size)
+    ssize_t rlsize = readlink(path.c_str(), buf, st.st_size);
+    if (rlsize == -1)
         throw SysError(format("reading symbolic link ‘%1%’") % path);
+    else if (rlsize != st.st_size)
+        throw Error(format("symbolic link ‘%1%’ size mismatch %2% != %3%")
+            % path % rlsize % st.st_size);
     return string(buf, st.st_size);
 }