Просмотр исходного кода

u-a: Do not try to readlink() a non-symlink

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.
Guillem Jover лет назад: 15
Родитель
Сommit
c922a8f681
1 измененных файлов с 6 добавлено и 0 удалено
  1. 6 0
      utils/update-alternatives.c

+ 6 - 0
utils/update-alternatives.c

@@ -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 */