From fb0998ac3ea5cc85569c5f89b004fa88959af2c0 Mon Sep 17 00:00:00 2001 From: Luiz Augusto Von Dentz Date: Mon, 14 Dec 2009 17:39:26 +0200 Subject: [PATCH] obexd: Fix string_read when reading chunks The chunks normally are not NUL terminate which might cause strlen to cause an invalid read. The fix is basically use GString len to calculate how much data can be copy in advance and use memcpy to do the job. --- obexd/plugins/filesystem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/obexd/plugins/filesystem.c b/obexd/plugins/filesystem.c index 1ca1b2763..ebb99d7f2 100644 --- a/obexd/plugins/filesystem.c +++ b/obexd/plugins/filesystem.c @@ -335,8 +335,8 @@ static ssize_t string_read(gpointer object, void *buf, size_t count) if (string->len == 0) return 0; - strncpy(buf, string->str, count); - len = strlen(buf); + len = count > string->len ? string->len : count; + memcpy(buf, string->str, len); string = g_string_erase(string, 0, len); return len; -- 2.47.3