Skip to content

Commit

Permalink
buffer: identify messages with length over the buffer limit
Browse files Browse the repository at this point in the history
Identify messages that are over the 4KiB buffer limit

Address issue reported downstream by Debian[1] and upstream by kaliko
(@mxjeff)[2]
[1] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=953110
[2] MusicPlayerDaemon#51
  • Loading branch information
cataldor committed Mar 27, 2020
1 parent 6f68c56 commit f8bc96c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/async.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,20 @@ mpd_async_copy_error(const struct mpd_async *async,
return mpd_error_copy(dest, &async->error);
}

bool
mpd_async_set_error(struct mpd_async *async, enum mpd_error error,
const char *error_message)
{
assert(async != NULL);

if (mpd_error_is_defined(&async->error))
return false;

mpd_error_code(&async->error, error);
mpd_error_message(&async->error, error_message);
return true;
}

int
mpd_async_get_fd(const struct mpd_async *async)
{
Expand Down
11 changes: 11 additions & 0 deletions src/iasync.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,15 @@ bool
mpd_async_copy_error(const struct mpd_async *async,
struct mpd_error_info *dest);

/**
* Sets the object's error condition.
*
* @return true if there was no error in #async, false if an error
* condition is stored in #async; the #error is only set if there was no error
* previously present
*/
bool
mpd_async_set_error(struct mpd_async *async, enum mpd_error error,
const char *error_message);

#endif
8 changes: 8 additions & 0 deletions src/sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "sync.h"
#include "socket.h"
#include "binary.h"
#include "iasync.h"

#include <mpd/async.h>

Expand Down Expand Up @@ -115,6 +116,13 @@ mpd_sync_send_command_v(struct mpd_async *async, const struct timeval *tv0,
success = mpd_async_send_command_v(async, command, copy);
va_end(copy);

/* no characters were written to async buffer */
if ((mpd_async_events(async) & MPD_ASYNC_EVENT_WRITE) == 0) {
(void)mpd_async_set_error(async, MPD_ERROR_OOM,
"Not enough buffer space for message");
return false;
}

if (success)
return true;

Expand Down

0 comments on commit f8bc96c

Please sign in to comment.