Skip to content

Commit 1ae2feb

Browse files
author
Michael Paquier
committed
Fix inconsistency in call of readlink()
If the target path is too long, an error needs to be emitted as well. The buffer is correctly null-terminated, this will just avoid running into weird problems should the target have a too long name.
1 parent b84334b commit 1ae2feb

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

dir.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,13 @@ dir_list_file_internal(parray *files, const char *root, const char *exclude[],
292292
char linked[MAXPGPATH];
293293

294294
len = readlink(file->path, linked, sizeof(linked));
295-
if (len == -1)
296-
{
295+
if (len < 0)
297296
elog(ERROR, "cannot read link \"%s\": %s", file->path,
298297
strerror(errno));
299-
}
298+
if (len >= sizeof(linked))
299+
elog(ERROR, "symbolic link \"%s\" target is too long\n",
300+
file->path);
301+
300302
linked[len] = '\0';
301303
file->linked = pgut_strdup(linked);
302304

0 commit comments

Comments
 (0)