Commit 27535a7f authored by Max Kellermann's avatar Max Kellermann

update_walk: fix unsafe readlink() usage

parent acaa7254
...@@ -17,6 +17,7 @@ ver 0.17.2 (2012/??/??) ...@@ -17,6 +17,7 @@ ver 0.17.2 (2012/??/??)
* playlist: fix memory leak * playlist: fix memory leak
* state_file: save song priorities * state_file: save song priorities
* player: disable cross-fading in "single" mode * player: disable cross-fading in "single" mode
* update: fix unsafe readlink() usage
ver 0.17.1 (2012/07/31) ver 0.17.1 (2012/07/31)
......
...@@ -283,12 +283,20 @@ skip_symlink(const struct directory *directory, const char *utf8_name) ...@@ -283,12 +283,20 @@ skip_symlink(const struct directory *directory, const char *utf8_name)
return true; return true;
char buffer[MPD_PATH_MAX]; char buffer[MPD_PATH_MAX];
ssize_t ret = readlink(path_fs, buffer, sizeof(buffer)); ssize_t length = readlink(path_fs, buffer, sizeof(buffer));
g_free(path_fs); g_free(path_fs);
if (ret < 0) if (length < 0)
/* don't skip if this is not a symlink */ /* don't skip if this is not a symlink */
return errno != EINVAL; return errno != EINVAL;
if ((size_t)length >= sizeof(buffer))
/* skip symlinks when the buffer is too small for the
link target */
return true;
/* null-terminate the buffer, because readlink() will not */
buffer[length] = 0;
if (!follow_inside_symlinks && !follow_outside_symlinks) { if (!follow_inside_symlinks && !follow_outside_symlinks) {
/* ignore all symlinks */ /* ignore all symlinks */
return true; return true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment