Made filesearch aware of symbolic links

(cherry picked from commit cbcbda1586d5a19cf17aabedb49bca3e5328fa4f)
This commit is contained in:
Sara Sparks 2023-05-06 20:46:46 -04:00
parent dc02339cc9
commit aa952051fd

View file

@ -23,6 +23,11 @@
#include <windows.h>
#endif
#include <sys/stat.h>
#ifndef IGNORE_SYMLINKS
#include <unistd.h>
#include <libgen.h>
#include <limits.h>
#endif
#include <string.h>
#include "filesrch.h"
@ -417,6 +422,9 @@ filestatus_t filesearch(char *filename, const char *startpath, const UINT8 *want
}
else if (!strcasecmp(searchname, dent->d_name))
{
#ifndef IGNORE_SYMLINKS
struct stat statbuf;
#endif
switch (checkfilemd5(searchpath, wantedmd5sum))
{
case FS_FOUND:
@ -424,6 +432,17 @@ filestatus_t filesearch(char *filename, const char *startpath, const UINT8 *want
strcpy(filename,searchpath);
else
strcpy(filename,dent->d_name);
#ifndef IGNORE_SYMLINKS
if (lstat(filename, &statbuf) != -1) {
if (S_ISLNK(statbuf.st_mode)) {
char *tempbuf = realpath(filename, NULL);
if (!tempbuf)
I_Error("Error parsing link %s: %s", filename, strerror(errno));
strncpy(filename, tempbuf, MAX_WADPATH);
free(tempbuf);
}
}
#endif
retval = FS_FOUND;
found = 1;
break;