mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-28 17:47:05 +03:00
libudev: path_encode - always return 0 if encoded string does not fit into size
This commit is contained in:
parent
9b144b8857
commit
3e5bafc98a
@ -15,7 +15,7 @@ test "$prefix" = NONE && test "$exec_prefix" = NONE && exec_prefix=
|
|||||||
|
|
||||||
dnl /* libudev version */
|
dnl /* libudev version */
|
||||||
LIBUDEV_LT_CURRENT=2
|
LIBUDEV_LT_CURRENT=2
|
||||||
LIBUDEV_LT_REVISION=0
|
LIBUDEV_LT_REVISION=1
|
||||||
LIBUDEV_LT_AGE=2
|
LIBUDEV_LT_AGE=2
|
||||||
AC_SUBST(LIBUDEV_LT_CURRENT)
|
AC_SUBST(LIBUDEV_LT_CURRENT)
|
||||||
AC_SUBST(LIBUDEV_LT_REVISION)
|
AC_SUBST(LIBUDEV_LT_REVISION)
|
||||||
|
@ -101,12 +101,12 @@ int util_log_priority(const char *priority)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t util_path_encode(char *s, size_t len)
|
size_t util_path_encode(char *s, size_t size)
|
||||||
{
|
{
|
||||||
char t[(len * 4)+1];
|
char t[(size * 4)+1];
|
||||||
size_t i, j;
|
size_t i, j;
|
||||||
|
|
||||||
for (i = 0, j = 0; s[i] != '\0'; i++) {
|
for (i = 0, j = 0; s[i] != '\0' && i < size; i++) {
|
||||||
if (s[i] == '/') {
|
if (s[i] == '/') {
|
||||||
memcpy(&t[j], "\\x2f", 4);
|
memcpy(&t[j], "\\x2f", 4);
|
||||||
j += 4;
|
j += 4;
|
||||||
@ -118,11 +118,12 @@ size_t util_path_encode(char *s, size_t len)
|
|||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (len == 0)
|
if (i >= size)
|
||||||
return j;
|
return 0;
|
||||||
i = (j < len - 1) ? j : len - 1;
|
if (j >= size)
|
||||||
memcpy(s, t, i);
|
return 0;
|
||||||
s[i] = '\0';
|
memcpy(s, t, j);
|
||||||
|
s[j] = '\0';
|
||||||
return j;
|
return j;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,7 +135,7 @@ size_t util_path_decode(char *s)
|
|||||||
if (memcmp(&s[i], "\\x2f", 4) == 0) {
|
if (memcmp(&s[i], "\\x2f", 4) == 0) {
|
||||||
s[j] = '/';
|
s[j] = '/';
|
||||||
i += 4;
|
i += 4;
|
||||||
}else if (memcmp(&s[i], "\\x5c", 4) == 0) {
|
} else if (memcmp(&s[i], "\\x5c", 4) == 0) {
|
||||||
s[j] = '\\';
|
s[j] = '\\';
|
||||||
i += 4;
|
i += 4;
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user