aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2008-01-29 09:22:39 +0000
committerEric Wong <normalperson@yhbt.net>2008-01-29 09:22:39 +0000
commit0700e55a62c329adfa8db0f81301b7ab8af76c45 (patch)
tree45352852be7042f8ca1d2c6cc287ad1012c86824 /src
parentdc14d0719c57f6c25048286eb6b1de2e445fb868 (diff)
downloadmpd-0700e55a62c329adfa8db0f81301b7ab8af76c45.tar.gz
mpd-0700e55a62c329adfa8db0f81301b7ab8af76c45.tar.xz
mpd-0700e55a62c329adfa8db0f81301b7ab8af76c45.zip
storedPlaylist: faster, but less accurate check for maximum sizes
There are still other ways to run the mpd server out of disk-space, so permissions are still recommended to protect against malicious users. git-svn-id: https://svn.musicpd.org/mpd/branches/branch-0.13.0-fixes@7178 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r--src/storedPlaylist.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/storedPlaylist.c b/src/storedPlaylist.c
index 0451316ea..daa97c76f 100644
--- a/src/storedPlaylist.c
+++ b/src/storedPlaylist.c
@@ -427,25 +427,25 @@ int appendSongToStoredPlaylistByPath(int fd, const char *utf8path, Song *song)
char *filename;
FILE *file;
char *s;
- int nr_songs = 0;
+ struct stat st;
char path_max_tmp[MAXPATHLEN + 1];
filename = utf8pathToFsPathInStoredPlaylist(utf8path, fd);
if (!filename)
return -1;
- while (!(file = fopen(filename, "a+")) && errno == EINTR);
+ while (!(file = fopen(filename, "a")) && errno == EINTR);
if (file == NULL) {
commandError(fd, ACK_ERROR_NO_EXIST, "could not open file "
"\"%s\": %s", filename, strerror(errno));
return -1;
}
- while (myFgets(path_max_tmp, sizeof(path_max_tmp), file)) {
- if (path_max_tmp[0] != PLAYLIST_COMMENT &&
- (++nr_songs >= playlist_max_length))
- break;
+ if (fstat(fileno(file), &st) < 0) {
+ commandError(fd, ACK_ERROR_NO_EXIST, "could not stat file "
+ "\"%s\": %s", path_max_tmp, strerror(errno));
+ return -1;
}
- if (nr_songs >= playlist_max_length) {
+ if (st.st_size >= ((MAXPATHLEN+1) * playlist_max_length)) {
commandError(fd, ACK_ERROR_PLAYLIST_MAX,
"playlist is at the max size");
return -1;