diff --git a/obexd/plugins/filesystem.c b/obexd/plugins/filesystem.c
index 041cca6..8d1d74b 100644
--- a/obexd/plugins/filesystem.c
+++ b/obexd/plugins/filesystem.c
static const uint8_t PCSUITE_WHO[PCSUITE_WHO_SIZE] = {
'P', 'C', ' ', 'S', 'u', 'i', 't', 'e' };
+gboolean is_filename(const char *name)
+{
+ if (strchr(name, '/'))
+ return FALSE;
+
+ if (strcmp(name, ".") == 0)
+ return FALSE;
+
+ if (strcmp(name, "..") == 0)
+ return FALSE;
+
+ return TRUE;
+}
static char *file_stat_line(char *filename, struct stat *fstat,
struct stat *dstat, gboolean root,
diff --git a/obexd/plugins/filesystem.h b/obexd/plugins/filesystem.h
index 9c7ad9a..3c6d2c1 100644
--- a/obexd/plugins/filesystem.h
+++ b/obexd/plugins/filesystem.h
*/
ssize_t string_read(void *object, void *buf, size_t count);
+gboolean is_filename(const char *name);
diff --git a/obexd/plugins/ftp.c b/obexd/plugins/ftp.c
index 8e17b6f..57b187c 100644
--- a/obexd/plugins/ftp.c
+++ b/obexd/plugins/ftp.c
#include "mimetype.h"
#include "service.h"
#include "ftp.h"
+#include "filesystem.h"
#define LST_TYPE "x-obex/folder-listing"
#define CAP_TYPE "x-obex/capability"
if (type != NULL && g_ascii_strcasecmp(type, CAP_TYPE) == 0)
return obex_get_stream_start(os, capability);
+ if (name != NULL && !is_filename(name))
+ return -EBADR;
+
path = g_build_filename(ftp->folder, name, NULL);
err = obex_get_stream_start(os, path);
if (name == NULL)
return -EBADR;
+ if (!is_filename(name))
+ return -EBADR;
+
if (size == OBJECT_SIZE_DELETE)
return ftp_delete(ftp, name);
}
/* Check and set to name path */
- if (strstr(name, "/") || strcmp(name, "..") == 0) {
+ if (!is_filename(name)) {
error("Set path failed: name incorrect!");
return -EPERM;
}
diff --git a/obexd/plugins/opp.c b/obexd/plugins/opp.c
index 5937110..644a2c6 100644
--- a/obexd/plugins/opp.c
+++ b/obexd/plugins/opp.c
#include "service.h"
#include "log.h"
#include "dbus.h"
+#include "filesystem.h"
#define VCARD_TYPE "text/x-vcard"
#define VCARD_FILE CONFIGDIR "/vcard.vcf"
char *path;
int32_t time;
int ret;
+ const char *t;
if (obex_get_size(os) == OBJECT_SIZE_DELETE)
return -EINVAL;
+ t = obex_get_name(os);
+ if (t != NULL && !is_filename(t))
+ return -EBADR;
+
if (obex_get_auto_accept(os)) {
folder = g_strdup(obex_get_root_folder(os));
name = g_strdup(obex_get_name(os));