diff options
author | Yossi Gottlieb <yossigo@gmail.com> | 2022-01-18 12:52:27 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-18 12:52:27 +0200 |
commit | 25e6d4d4597d6ca06503d5fa76af0e4e1b57302e (patch) | |
tree | 66e78300bc0ec4983c0223e17a3065aa6793146c /src/sds.c | |
parent | 51f9bed3dd8d35a59e9124e49450c9795822dbf5 (diff) | |
download | redis-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.c | 20 |
1 files changed, 20 insertions, 0 deletions
@@ -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) { |