copy_arg: fix copying an escaped backslash

GitHub issue #179
This commit is contained in:
Todd C. Miller
2022-09-23 12:30:51 -06:00
parent d37710b0f6
commit e66f34d250
2 changed files with 12 additions and 5 deletions

View File

@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: ISC
*
* Copyright (c) 2010-2015 Todd C. Miller <Todd.Miller@sudo.ws>
* Copyright (c) 2010-2015, 2020-2022 Todd C. Miller <Todd.Miller@sudo.ws>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -103,10 +103,8 @@ copy_arg(const char *src, size_t len)
if ((copy = malloc(len + 1)) != NULL) {
sudoers_gc_add(GC_PTR, copy);
for (dst = copy; src < src_end; ) {
if (src[0] == '\\' && src[1] != '\0') {
if (src[0] == '\\' && src[1] != '\0')
src++;
continue;
}
*dst++ = *src++;
}
*dst = '\0';

View File

@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: ISC
*
* Copyright (c) 2021 Todd C. Miller <Todd.Miller@sudo.ws>
* Copyright (c) 2021-2022 Todd C. Miller <Todd.Miller@sudo.ws>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -63,6 +63,15 @@ struct test_data {
3,
{ "/usr/bin/vi\\", "--", "/etc/hosts", "/bogus/file", NULL }
},
{
/* GitHub issue #179 */
"EDITOR=sed -rie s/^\\\\(foo\\\\)/waldo\\\\1/",
1,
{ "/etc/sudoers", NULL },
"/usr/bin/sed",
5,
{ "sed", "-rie", "s/^\\(foo\\)/waldo\\1/", "--", "/etc/sudoers", NULL }
},
{ NULL }
};