Fixed following symbolic links in RemoveFileOrDir()

This commit is contained in:
Klaus Schmidinger 2010-08-29 15:03:08 +02:00
parent 5203fa03e8
commit 2009716599
2 changed files with 25 additions and 15 deletions

View File

@ -6477,3 +6477,4 @@ Video Disk Recorder Revision History
- Added locking to the cCutter functions to avoid a crash in case CutRecording() - Added locking to the cCutter functions to avoid a crash in case CutRecording()
is called from a plugin (reported by Andreas Mair). is called from a plugin (reported by Andreas Mair).
- Fixed DDS detection for HD resolution subtitles (thanks to Reinhard Nissl). - Fixed DDS detection for HD resolution subtitles (thanks to Reinhard Nissl).
- Fixed following symbolic links in RemoveFileOrDir().

39
tools.c
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: tools.c 2.7 2010/02/28 13:31:46 kls Exp $ * $Id: tools.c 2.8 2010/08/29 15:03:08 kls Exp $
*/ */
#include "tools.h" #include "tools.h"
@ -367,22 +367,31 @@ bool RemoveFileOrDir(const char *FileName, bool FollowSymlinks)
if (strcmp(e->d_name, ".") && strcmp(e->d_name, "..")) { if (strcmp(e->d_name, ".") && strcmp(e->d_name, "..")) {
cString buffer = AddDirectory(FileName, e->d_name); cString buffer = AddDirectory(FileName, e->d_name);
if (FollowSymlinks) { if (FollowSymlinks) {
int size = strlen(buffer) * 2; // should be large enough struct stat st2;
char *l = MALLOC(char, size); if (stat(buffer, &st2) == 0) {
int n = readlink(buffer, l, size); if (S_ISLNK(st2.st_mode)) {
if (n < 0) { int size = st2.st_size + 1;
if (errno != EINVAL) char *l = MALLOC(char, size);
LOG_ERROR_STR(*buffer); int n = readlink(buffer, l, size - 1);
if (n < 0) {
if (errno != EINVAL)
LOG_ERROR_STR(*buffer);
}
else if (n < size) {
l[n] = 0;
dsyslog("removing %s", l);
if (remove(l) < 0)
LOG_ERROR_STR(l);
}
else
esyslog("ERROR: symlink name length (%d) exceeded anticipated buffer size (%d)", n, size);
free(l);
}
} }
else if (n < size) { else if (errno != ENOENT) {
l[n] = 0; LOG_ERROR_STR(FileName);
dsyslog("removing %s", l); return false;
if (remove(l) < 0)
LOG_ERROR_STR(l);
} }
else
esyslog("ERROR: symlink name length (%d) exceeded anticipated buffer size (%d)", n, size);
free(l);
} }
dsyslog("removing %s", *buffer); dsyslog("removing %s", *buffer);
if (remove(buffer) < 0) if (remove(buffer) < 0)