Skip to content

Commit

Permalink
Fix bug related to /x00
Browse files Browse the repository at this point in the history
Signed-off-by: Madelyn Olson <[email protected]>
  • Loading branch information
madolson committed Oct 25, 2024
1 parent d5b4cd6 commit 0d7514b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/sds.c
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,7 @@ static int sdsparsearg(const char *arg, unsigned int *len, char *dst) {
int done = 0;

while (!done) {
char new_char = 0;
int new_char = -1;
if (inq) {
if (*p == '\\' && *(p + 1) == 'x' && is_hex_digit(*(p + 2)) && is_hex_digit(*(p + 3))) {
new_char = (hex_digit_to_int(*(p + 2)) * 16) + hex_digit_to_int(*(p + 3));
Expand Down Expand Up @@ -1098,10 +1098,10 @@ static int sdsparsearg(const char *arg, unsigned int *len, char *dst) {
default: new_char = *p; break;
}
}
if (new_char) {
if (new_char != -1) {
if (len) (*len)++;
if (dst) {
*dst = new_char;
*dst = (char) new_char;
dst++;
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/unit/test_sds.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,9 @@ int test_sdsHeaderSizes(int argc, char **argv, int flags) {
return 0;
}

static sds *sdssplitargs_legacy(const char *line, int *argc);


int test_sdssplitargs(int argc, char **argv, int flags) {
UNUSED(argc);
UNUSED(argv);
Expand Down Expand Up @@ -363,6 +366,11 @@ int test_sdssplitargs(int argc, char **argv, int flags) {
TEST_ASSERT(!strcmp("Hello", sargv[0]));
sdsfreesplitres(sargv, len);

char *binary_string = "\"\\x73\\x75\\x70\\x65\\x72\\x20\\x00\\x73\\x65\\x63\\x72\\x65\\x74\\x20\\x70\\x61\\x73\\x73\\x77\\x6f\\x72\\x64\"";
sargv = sdssplitargs_legacy(binary_string, &len);
TEST_ASSERT(1 == len);
TEST_ASSERT(22 == sdslen(sargv[0]));

return 0;
}

Expand Down

0 comments on commit 0d7514b

Please sign in to comment.