chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
util: make sure rm_rf() can be called on symlinks (with the effect of deleting it)
[elogind.git]
/
src
/
shared
/
util.c
diff --git
a/src/shared/util.c
b/src/shared/util.c
index 364f61885b00a1b3f9a076a993b982f74468ba7e..dbae55fe38d127014d1c9b107695d4c48a5246fb 100644
(file)
--- a/
src/shared/util.c
+++ b/
src/shared/util.c
@@
-521,7
+521,7
@@
int safe_atod(const char *s, double *ret_d) {
static size_t strcspn_escaped(const char *s, const char *reject) {
bool escaped = false;
static size_t strcspn_escaped(const char *s, const char *reject) {
bool escaped = false;
-
size_
t n;
+
in
t n;
for (n=0; s[n]; n++) {
if (escaped)
for (n=0; s[n]; n++) {
if (escaped)
@@
-531,6
+531,7
@@
static size_t strcspn_escaped(const char *s, const char *reject) {
else if (strchr(reject, s[n]))
break;
}
else if (strchr(reject, s[n]))
break;
}
+
/* if s ends in \, return index of previous char */
return n - escaped;
}
/* if s ends in \, return index of previous char */
return n - escaped;
}
@@
-566,6
+567,11
@@
const char* split(const char **state, size_t *l, const char *separator, bool quo
*state = current++ + *l + 2;
} else if (quoted) {
*l = strcspn_escaped(current, separator);
*state = current++ + *l + 2;
} else if (quoted) {
*l = strcspn_escaped(current, separator);
+ if (current[*l] && !strchr(separator, current[*l])) {
+ /* unfinished escape */
+ *state = current;
+ return NULL;
+ }
*state = current + *l;
} else {
*l = strcspn(current, separator);
*state = current + *l;
} else {
*l = strcspn(current, separator);
@@
-3063,7
+3069,7
@@
static int rm_rf_internal(const char *path, bool only_dirs, bool delete_root, bo
fd = open(path, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|O_NOFOLLOW|O_NOATIME);
if (fd < 0) {
fd = open(path, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|O_NOFOLLOW|O_NOATIME);
if (fd < 0) {
- if (errno != ENOTDIR)
+ if (errno != ENOTDIR
&& errno != ELOOP
)
return -errno;
if (!dangerous) {
return -errno;
if (!dangerous) {