summaryrefslogtreecommitdiff
path: root/src/sds.c
diff options
context:
space:
mode:
authorYossi Gottlieb <yossigo@gmail.com>2022-01-18 12:52:27 +0200
committerGitHub <noreply@github.com>2022-01-18 12:52:27 +0200
commit25e6d4d4597d6ca06503d5fa76af0e4e1b57302e (patch)
tree66e78300bc0ec4983c0223e17a3065aa6793146c /src/sds.c
parent51f9bed3dd8d35a59e9124e49450c9795822dbf5 (diff)
downloadredis-25e6d4d4597d6ca06503d5fa76af0e4e1b57302e.tar.gz
Fix additional AOF filename issues. (#10110)
This extends the previous fix (#10049) to address any form of non-printable or whitespace character (including newlines, quotes, non-printables, etc.) Also, removes the limitation on appenddirname, to align with the way filenames are handled elsewhere in Redis.
Diffstat (limited to 'src/sds.c')
-rw-r--r--src/sds.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/sds.c b/src/sds.c
index a625c66b7..4e934d7ad 100644
--- a/src/sds.c
+++ b/src/sds.c
@@ -1021,6 +1021,26 @@ sds sdscatrepr(sds s, const char *p, size_t len) {
return sdscatlen(s,"\"",1);
}
+/* Returns one if the string contains characters to be escaped
+ * by sdscatrepr(), zero otherwise.
+ *
+ * Typically, this should be used to help protect aggregated strings in a way
+ * that is compatible with sdssplitargs(). For this reason, also spaces will be
+ * treated as needing an escape.
+ */
+int sdsneedsrepr(const sds s) {
+ size_t len = sdslen(s);
+ const char *p = s;
+
+ while (len--) {
+ if (*p == '\\' || *p == '"' || *p == '\n' || *p == '\r' ||
+ *p == '\t' || *p == '\a' || *p == '\b' || !isprint(*p) || isspace(*p)) return 1;
+ p++;
+ }
+
+ return 0;
+}
+
/* Helper function for sdssplitargs() that returns non zero if 'c'
* is a valid hex digit. */
int is_hex_digit(char c) {