summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-11-01 13:36:55 +0100
committerwm4 <wm4@nowhere>2014-11-01 15:45:40 +0100
commita1e7daf9429a2052a20df133cc9c7f8335071c22 (patch)
treebd09313fd75f34cdf7d69e67b789840240a5c40f
parentd915ef7f0f8e4ca04bd6ff7c710705569e48f174 (diff)
downloadmpv-a1e7daf9429a2052a20df133cc9c7f8335071c22.tar.bz2
mpv-a1e7daf9429a2052a20df133cc9c7f8335071c22.tar.xz
ipc: verify resume/suspend commands
Calling mpv_resume() too often is considered an API usage violation, and will trigger an internal assertion somewhere.
-rw-r--r--input/ipc.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/input/ipc.c b/input/ipc.c
index 3d2a35f558..1fb096842b 100644
--- a/input/ipc.c
+++ b/input/ipc.c
@@ -60,6 +60,8 @@ struct client_arg {
int client_fd;
bool writable;
+
+ int suspend_counter;
};
static mpv_node *mpv_node_map_get(mpv_node *src, const char *key)
@@ -409,11 +411,21 @@ static char *json_execute_command(struct client_arg *arg, void *ta_parent,
rc = mpv_unobserve_property(arg->client,
cmd_node->u.list->values[1].u.int64);
} else if (!strcmp("suspend", cmd)) {
- mpv_suspend(arg->client);
- rc = MPV_ERROR_SUCCESS;
+ if (arg->suspend_counter < INT_MAX) {
+ mpv_suspend(arg->client);
+ arg->suspend_counter++;
+ rc = MPV_ERROR_SUCCESS;
+ } else {
+ rc = MPV_ERROR_INVALID_PARAMETER;
+ }
} else if (!strcmp("resume", cmd)) {
- mpv_resume(arg->client);
- rc = MPV_ERROR_SUCCESS;
+ if (arg->suspend_counter > 0) {
+ mpv_resume(arg->client);
+ arg->suspend_counter--;
+ rc = MPV_ERROR_SUCCESS;
+ } else {
+ rc = MPV_ERROR_INVALID_PARAMETER;
+ }
} else {
mpv_node result_node;