aboutsummaryrefslogtreecommitdiffstats
path: root/thermometer/thermometer.c
diff options
context:
space:
mode:
authorSantiago Carot-Nemesio <sancane@gmail.com>2011-12-09 19:19:03 +0100
committerJohan Hedberg <johan.hedberg@intel.com>2011-12-15 13:24:23 +0200
commit3cda922eead61ba0a862924bf49246d81e9b1669 (patch)
tree60ce96598d8b6643d70638239eb8fdd9cf349190 /thermometer/thermometer.c
parent726dc13a33ef1a73854521f9306536904b48eb93 (diff)
downloadbluez-3cda922eead61ba0a862924bf49246d81e9b1669.tar.gz
bluez-3cda922eead61ba0a862924bf49246d81e9b1669.tar.xz
bluez-3cda922eead61ba0a862924bf49246d81e9b1669.zip
thermometer: Fix bad read operation when time stamp is not provided
Time stamp value is an optional field provided in the measure, so next value in the array will start in a different index depending if the time stamp was provided or not. This patch check this case and update the index to a proper value in the byte array before reading the temperature type value.
Diffstat (limited to 'thermometer/thermometer.c')
-rw-r--r--thermometer/thermometer.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/thermometer/thermometer.c b/thermometer/thermometer.c
index e78d250e..e8da73f3 100644
--- a/thermometer/thermometer.c
+++ b/thermometer/thermometer.c
@@ -1072,12 +1072,18 @@ static void proc_measurement(struct thermometer *t, const uint8_t *pdu,
m.suptime = FALSE;
if (flags & TEMP_TYPE) {
- if (len < 16) {
+ uint8_t index;
+
+ if (m.suptime && len >= 16)
+ index = 15;
+ else if (!m.suptime && len >= 9)
+ index = 9;
+ else {
DBG("Can't get temperature type");
return;
}
- type = temptype2str(pdu[15]);
+ type = temptype2str(pdu[index]);
} else if (t->has_type)
type = temptype2str(t->type);
else {