summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Ranostay <matt.ranostay@konsulko.com>2019-07-29 11:51:32 -0700
committerJan-Simon Moeller <jsmoeller@linuxfoundation.org>2019-08-01 16:14:54 +0000
commitffa4b099f5c70aee02bdc041239793f126a78ec4 (patch)
tree4026cc524e4ff2e63ebab7d6755d01c5d31b3aba
parentebbc2361609f58791770c3e71dd3355b22eb57ad (diff)
Avoid segfaulting if obex data transfer result cannot be accessed due to permissions. Bug-AGL: SPEC-2695 Change-Id: Iae75af3e44f7e8265f1a9a52d2343d358c985bfc Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com>
-rw-r--r--binding/bluetooth-pbap-binding.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/binding/bluetooth-pbap-binding.c b/binding/bluetooth-pbap-binding.c
index 0e0a27c..e2f5c55 100644
--- a/binding/bluetooth-pbap-binding.c
+++ b/binding/bluetooth-pbap-binding.c
@@ -161,6 +161,9 @@ static char *get_vcard_xfer(gchar *filename)
size_t size, n;
fp = fopen(filename, "ro");
+ if (!fp)
+ return NULL;
+
fseek(fp, 0L, SEEK_END);
size = ftell(fp);
vcard_data = calloc(1, size);
@@ -274,7 +277,7 @@ static gchar *pull_vcards(int max_entries)
static json_object *get_vcards(int max_entries)
{
- json_object *vcards;
+ json_object *vcards = NULL;
gchar *tpath, *filename, *vcards_str = NULL;
tpath = pull_vcards(max_entries);
@@ -287,10 +290,11 @@ static json_object *get_vcards(int max_entries)
g_hash_table_remove(xfer_complete, tpath);
g_mutex_unlock(&xfer_complete_mutex);
- vcards = json_object_new_object();
- json_object_object_add(vcards, "vcards", parse_vcards(vcards_str));
- g_free(vcards_str);
-
+ if (vcards_str) {
+ vcards = json_object_new_object();
+ json_object_object_add(vcards, "vcards", parse_vcards(vcards_str));
+ g_free(vcards_str);
+ }
return vcards;
}