aboutsummaryrefslogtreecommitdiffstats
path: root/src/storedPlaylist.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/storedPlaylist.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/storedPlaylist.c b/src/storedPlaylist.c
index b0d66fb10..69eb34807 100644
--- a/src/storedPlaylist.c
+++ b/src/storedPlaylist.c
@@ -129,6 +129,9 @@ List *loadStoredPlaylist(int fd, const char *utf8path)
insertInListWithoutKey(list, xstrdup(path_max_tmp));
} else if (isValidRemoteUtf8Url(s))
insertInListWithoutKey(list, xstrdup(s));
+
+ if (list->numberOfNodes >= playlist_max_length)
+ break;
}
while (fclose(file) && errno == EINTR);
@@ -284,6 +287,7 @@ int appendSongToStoredPlaylistByPath(int fd, const char *utf8path, Song *song)
{
FILE *file;
char *s;
+ int nr_songs = 0;
char path_max_tmp[MPD_PATH_MAX];
char path_max_tmp2[MPD_PATH_MAX];
@@ -291,12 +295,22 @@ 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 (nr_songs >= playlist_max_length) {
+ commandError(fd, ACK_ERROR_PLAYLIST_MAX,
+ "playlist is at the max size");
+ return -1;
+ }
s = utf8_to_fs_charset(path_max_tmp2, get_song_url(path_max_tmp, song));