diff options
author | Eric Wong <normalperson@yhbt.net> | 2008-01-29 09:26:39 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2008-01-29 09:26:39 +0000 |
commit | 22efbd5eca4705426af5cee17a65a3e76c33bec6 (patch) | |
tree | f72b84a52190e0754c3ccd79b762e3d031c4ade3 /src/storedPlaylist.c | |
parent | b1cbe333a6b55ed27c8ef9d8b2731eec5b3d4c30 (diff) | |
download | mpd-22efbd5eca4705426af5cee17a65a3e76c33bec6.tar.gz mpd-22efbd5eca4705426af5cee17a65a3e76c33bec6.tar.xz mpd-22efbd5eca4705426af5cee17a65a3e76c33bec6.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/trunk@7179 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src/storedPlaylist.c')
-rw-r--r-- | src/storedPlaylist.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/storedPlaylist.c b/src/storedPlaylist.c index 69eb34807..c936d61f9 100644 --- a/src/storedPlaylist.c +++ b/src/storedPlaylist.c @@ -287,7 +287,7 @@ int appendSongToStoredPlaylistByPath(int fd, const char *utf8path, Song *song) { FILE *file; char *s; - int nr_songs = 0; + struct stat st; char path_max_tmp[MPD_PATH_MAX]; char path_max_tmp2[MPD_PATH_MAX]; @@ -295,18 +295,18 @@ int appendSongToStoredPlaylistByPath(int fd, const char *utf8path, Song *song) return -1; utf8_to_fs_playlist_path(path_max_tmp, utf8path); - while (!(file = fopen(path_max_tmp, "a+")) && errno == EINTR); + while (!(file = fopen(path_max_tmp, "a")) && errno == EINTR); if (file == NULL) { commandError(fd, ACK_ERROR_NO_EXIST, "could not open file " "\"%s\": %s", path_max_tmp, 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 >= ((MPD_PATH_MAX+1) * playlist_max_length)) { commandError(fd, ACK_ERROR_PLAYLIST_MAX, "playlist is at the max size"); return -1; |