reds: Fix one case parsing invalid codec string

In case we pass something like "spice:mjpeg$%*" the last part is
ignore making the string parse correctly.
A single pair should end by either string terminator or pair terminator.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
This commit is contained in:
Frediano Ziglio 2018-06-26 10:52:11 +01:00
parent f4632931d5
commit 3f6ac2bccf
2 changed files with 13 additions and 3 deletions

View File

@ -3563,10 +3563,14 @@ static const char* parse_next_video_codec(const char *codecs, char **encoder,
}
int n;
*encoder = *codec = NULL;
if (sscanf(codecs, "%m[0-9a-zA-Z_]:%m[0-9a-zA-Z_]%n", encoder, codec, &n) != 2) {
return codecs + strcspn(codecs, ";");
if (sscanf(codecs, "%m[0-9a-zA-Z_]:%m[0-9a-zA-Z_]%n", encoder, codec, &n) == 2) {
// this avoids accepting "encoder:codec" followed by garbage like "$%*"
if (codecs[n] != ';' && codecs[n] != '\0') {
free(*codec);
*codec = NULL;
}
}
return codecs + n;
return codecs + strcspn(codecs, ";");
}
static void reds_set_video_codecs_from_string(RedsState *reds, const char *codecs)

View File

@ -115,6 +115,12 @@ static void codecs_bad(void)
G_LOG_LEVEL_WARNING,
"*spice: invalid encoder:codec value*",
TRUE,
},{
// invalid character in codec
"spice:mjpeg&",
G_LOG_LEVEL_WARNING,
"*spice: invalid encoder:codec value*",
TRUE,
},
#if !defined(HAVE_GSTREAMER_1_0) && !defined(HAVE_GSTREAMER_0_10)
{