dbus: add some more safety checks before accepting data from bus clients
This commit is contained in:
@@ -56,6 +56,7 @@
|
||||
#include <sys/mman.h>
|
||||
#include <sys/vfs.h>
|
||||
#include <linux/magic.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "macro.h"
|
||||
#include "util.h"
|
||||
@@ -5851,3 +5852,39 @@ void closedirp(DIR **d) {
|
||||
void umaskp(mode_t *u) {
|
||||
umask(*u);
|
||||
}
|
||||
|
||||
bool filename_is_safe(const char *p) {
|
||||
|
||||
if (isempty(p))
|
||||
return false;
|
||||
|
||||
if (strchr(p, '/'))
|
||||
return false;
|
||||
|
||||
if (streq(p, "."))
|
||||
return false;
|
||||
|
||||
if (streq(p, ".."))
|
||||
return false;
|
||||
|
||||
if (strlen(p) > FILENAME_MAX)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool string_is_safe(const char *p) {
|
||||
const char *t;
|
||||
|
||||
assert(p);
|
||||
|
||||
for (t = p; *t; t++) {
|
||||
if (*p < ' ')
|
||||
return false;
|
||||
|
||||
if (strchr("\\\"\'", *p))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -558,3 +558,6 @@ _malloc_ static inline void *memdup_multiply(const void *p, size_t a, size_t b)
|
||||
|
||||
return memdup(p, a * b);
|
||||
}
|
||||
|
||||
bool filename_is_safe(const char *p);
|
||||
bool string_is_safe(const char *p);
|
||||
|
||||
Reference in New Issue
Block a user