Return early in case the path is not a symlink, there's no point in calling readlink() if we know it's going to fail.
@@ -289,6 +289,12 @@ areadlink(const char *linkname)
/* Allocate required memory to store the value of the symlink */
if (lstat(linkname, &st))
return NULL;
+
+ if (!S_ISLNK(st.st_mode)) {
+ errno = EINVAL;
+ return NULL;
+ }
buf = xmalloc(st.st_size + 1);
/* Read it and terminate the string properly */