From 8a8437634a2dc58768172f481ccf3c6637745d46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Eric=20Janouch?= Date: Wed, 7 Aug 2024 22:04:00 +0200 Subject: [PATCH] MPD client: fix argument quoting --- liberty-proto.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/liberty-proto.c b/liberty-proto.c index 577fcda..d4355c7 100644 --- a/liberty-proto.c +++ b/liberty-proto.c @@ -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); }