handover: Try to send HS only if message preparation succeed
authorSzymon Janc <szymon.janc@tieto.com>
Fri, 21 Sep 2012 14:48:30 +0000 (16:48 +0200)
committerSamuel Ortiz <sameo@linux.intel.com>
Mon, 1 Oct 2012 08:16:52 +0000 (10:16 +0200)
near_ndef_prepare_handover_record can return NULL in message
preparation failed e.g. due to failure in requesting data from handover
agent. This could result in crash due to NULL pointer dereference.

plugins/handover.c

index 642bf47..5d6c087 100644 (file)
@@ -142,6 +142,10 @@ static int handover_ndef_parse(int client_fd, struct hr_ndef *ndef)
                 */
                msg = near_ndef_prepare_handover_record("Hs", records->data,
                                                        NEAR_CARRIER_BLUETOOTH);
+               if (msg == NULL) {
+                       err = -EINVAL;
+                       goto fail;
+               }
 
                near_info("Send Hs frame");
                err = send(client_fd, msg->data, msg->length, MSG_DONTWAIT);