MPD client: fix argument quoting
All checks were successful
Alpine 3.20 Success

This commit is contained in:
Přemysl Eric Janouch 2024-08-07 22:04:00 +02:00
parent e78b410a6a
commit 8a8437634a
Signed by: p
GPG Key ID: A0420B94F92B9493

View File

@ -1635,30 +1635,30 @@ mpd_client_on_ready (const struct pollfd *pfd, void *user_data)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
static bool
mpd_client_must_quote_char (char c)
{
return (unsigned char) c <= ' ' || c == '"' || c == '\'';
}
static bool
mpd_client_must_quote (const char *s)
{
if (!*s)
return true;
for (; *s; s++)
if (mpd_client_must_quote_char (*s))
if ((unsigned char) *s <= ' ' || *s == '"' || *s == '\'')
return true;
return false;
}
static bool
mpd_client_must_escape_in_quote (char c)
{
return c == '"' || c == '\'' || c == '\\';
}
static void
mpd_client_quote (const char *s, struct str *output)
{
str_append_c (output, '"');
for (; *s; s++)
{
if (mpd_client_must_quote_char (*s))
if (mpd_client_must_escape_in_quote (*s))
str_append_c (output, '\\');
str_append_c (output, *s);
}