From 4c301883a5a94a9a186a1bb1d45d234db4db7c88 Mon Sep 17 00:00:00 2001 From: Dominik Neudert-Schulz Date: Wed, 30 Jun 2021 14:13:46 +0200 Subject: [PATCH] fix rpmbuild failure because of wrong symlink length on some filesystems --- build/files.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/build/files.c b/build/files.c index f8153ad2b5..571b502e91 100644 --- a/build/files.c +++ b/build/files.c @@ -1363,6 +1363,8 @@ static rpmRC addFile(FileList fl, const char * diskPath, { size_t plen = strlen(diskPath); char buf[plen + 1]; + char linkPath[PATH_MAX]; + ssize_t linkLen; const char *cpioPath; struct stat statbuf; mode_t fileMode; @@ -1459,6 +1461,20 @@ static rpmRC addFile(FileList fl, const char * diskPath, fileUid = statp->st_uid; fileGid = statp->st_gid; + if (S_ISLNK(fileMode)) { + /* stat's man page states that statp->st_size should equal the length of + the pointed-to path. On some filesystem a wrong size is reported. + So, explicitly get the length here. */ + linkLen = readlink(diskPath, linkPath, sizeof(linkPath)); + if ((linkLen < 0) || (linkLen >= sizeof(linkPath))) { + rpmlog(RPMLOG_ERR, + "Symbolic link too long or corrupt: %s\n", + diskPath); + goto exit; + } + statp->st_size = linkLen; + } + /* Explicit %attr() always wins */ if (fl->cur.ar.ar_fmodestr) { if (S_ISLNK(fileMode)) {