com_jmp(): Handle negative values gracefully.
authorAndre Noll <maan@tuebingen.mpg.de>
Sat, 3 Jul 2021 12:36:43 +0000 (14:36 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Mon, 30 Aug 2021 18:36:10 +0000 (20:36 +0200)
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

index 8ea725de7898ef817a62c0ba2755c73a0f744572..0a76f68ee03dfeadf2d48e0b5065594caecbfef0 100644 (file)
--- 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;