From dc659692881378cd174593c63a5675b2baba7c71 Mon Sep 17 00:00:00 2001 From: Luiz Augusto Von Dentz Date: Fri, 18 Dec 2009 15:51:49 +0200 Subject: [PATCH] obexd: Fix bug when object size is unknown When object size is unknown we set the size as being -1 which is then cast to size_t * which is incorrect and may cause ENOSPC. To fix it the unknown object size is now passed as NULL pointer to the open callback which will just skip free space check as we don't know how much data is to be written. --- obexd/plugins/filesystem.c | 8 ++++++-- obexd/src/obex.c | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/obexd/plugins/filesystem.c b/obexd/plugins/filesystem.c index 6660b583b..ae7ceea69 100644 --- a/obexd/plugins/filesystem.c +++ b/obexd/plugins/filesystem.c @@ -138,14 +138,18 @@ static gpointer filesystem_open(const char *name, int oflag, mode_t mode, } if (oflag == O_RDONLY) { - *size = stats.st_size; + if (size) + *size = stats.st_size; return GINT_TO_POINTER(fd); } if (fstatvfs(fd, &buf) < 0) goto failed; - if (buf.f_bsize * buf.f_bavail < *size) { + if (size == NULL) + return GINT_TO_POINTER(fd); + + if (buf.f_bsize * buf.f_bavail < (size_t) *size) { errno = ENOSPC; goto failed; } diff --git a/obexd/src/obex.c b/obexd/src/obex.c index 192b3dd98..d0afc18a5 100644 --- a/obexd/src/obex.c +++ b/obexd/src/obex.c @@ -467,9 +467,9 @@ gint os_prepare_put(struct obex_session *os) gint len; path = g_build_filename(os->current_folder, os->name, NULL); - os->object = os->driver->open(path, O_WRONLY | O_CREAT | O_TRUNC, 0600, - (size_t *) &os->size); + os->size != OBJECT_SIZE_UNKNOWN ? + (size_t *) &os->size : NULL); if (os->object == NULL) { error("open(%s): %s (%d)", path, strerror(errno), errno); g_free(path); -- 2.47.3