From d6a87acd98b9e451d488e31b92cdae7673c30ac6 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sat, 3 Jul 2021 14:36:43 +0200 Subject: [PATCH] com_jmp(): Handle negative values gracefully. Currently these get silently converted to a (large) unsigned number, which causes para_server to skip to the next audio file. This patch modifies the command handler to check whether the given value is within range and fails the command if it is out of range. Remove an uninteresting log message while at it. --- command.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/command.c b/command.c index 8ea725de..0a76f68e 100644 --- a/command.c +++ b/command.c @@ -717,8 +717,7 @@ EXPORT_SERVER_CMD_HANDLER(ff); static int com_jmp(struct command_context *cc, struct lls_parse_result *lpr) { - long unsigned int i; - int ret; + int i, ret; char *errctx; ret = lls(lls_check_arg_count(lpr, 1, 1, &errctx)); @@ -726,18 +725,16 @@ static int com_jmp(struct command_context *cc, struct lls_parse_result *lpr) send_errctx(cc, errctx); return ret; } - if (sscanf(lls_input(0, lpr), "%lu", &i) <= 0) + if (sscanf(lls_input(0, lpr), "%d", &i) <= 0) + return -ERRNO_TO_PARA_ERROR(EINVAL); + if (i < 0 || i > 100) return -ERRNO_TO_PARA_ERROR(EINVAL); mutex_lock(mmd_mutex); ret = -E_NO_AUDIO_FILE; if (!mmd->afd.afhi.chunks_total) goto out; - if (i > 100) - i = 100; - PARA_INFO_LOG("jumping to %lu%%\n", i); + PARA_INFO_LOG("jumping to %d%%\n", i); mmd->repos_request = (mmd->afd.afhi.chunks_total * i + 50) / 100; - PARA_INFO_LOG("sent: %lu, offset before jmp: %li\n", - mmd->chunks_sent, mmd->offset); mmd->new_vss_status_flags |= VSS_REPOS; mmd->new_vss_status_flags &= ~VSS_NEXT; ret = 1; -- 2.39.5