forked from AndDiSa/platform_manifest-Grouper-AOSP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
system_bt.patch
4495 lines (4147 loc) · 170 KB
/
system_bt.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
diff --git a/bta/ag/bta_ag_act.c b/bta/ag/bta_ag_act.c
index 285a967c5..2d0e75ad8 100644
--- a/bta/ag/bta_ag_act.c
+++ b/bta/ag/bta_ag_act.c
@@ -68,7 +68,7 @@ const tBTA_SERVICE_MASK bta_ag_svc_mask[BTA_AG_NUM_IDX] =
};
typedef void (*tBTA_AG_ATCMD_CBACK)(tBTA_AG_SCB *p_scb, UINT16 cmd, UINT8 arg_type,
- char *p_arg, INT16 int_arg);
+ char *p_arg, char* p_end, INT16 int_arg);
const tBTA_AG_ATCMD_CBACK bta_ag_at_cback_tbl[BTA_AG_NUM_IDX] =
{
diff --git a/bta/ag/bta_ag_at.c b/bta/ag/bta_ag_at.c
index 36061756d..2621b0997 100644
--- a/bta/ag/bta_ag_at.c
+++ b/bta/ag/bta_ag_at.c
@@ -25,6 +25,7 @@
#include <string.h>
#include "bt_common.h"
#include "bta_ag_at.h"
+#include "log/log.h"
#include "utl.h"
/*****************************************************************************
@@ -77,7 +78,7 @@ void bta_ag_at_reinit(tBTA_AG_AT_CB *p_cb)
** Returns void
**
******************************************************************************/
-void bta_ag_process_at(tBTA_AG_AT_CB *p_cb)
+void bta_ag_process_at(tBTA_AG_AT_CB *p_cb, char* p_end)
{
UINT16 idx;
UINT8 arg_type;
@@ -97,7 +98,11 @@ void bta_ag_process_at(tBTA_AG_AT_CB *p_cb)
{
/* start of argument is p + strlen matching command */
p_arg = p_cb->p_cmd_buf + strlen(p_cb->p_at_tbl[idx].p_cmd);
-
+ if (p_arg > p_end) {
+ //(*p_cb->p_err_cback)((tBTA_AG_SCB*)p_cb->p_user, false, nullptr);
+ android_errorWriteLog(0x534e4554, "112860487");
+ return;
+ }
/* if no argument */
if (p_arg[0] == 0)
{
@@ -151,14 +156,14 @@ void bta_ag_process_at(tBTA_AG_AT_CB *p_cb)
(*p_cb->p_cmd_cback)(p_cb->p_user,
p_cb->p_at_tbl[idx].command_id,
- arg_type, p_arg, int_arg);
+ arg_type, p_arg, p_end, int_arg);
}
}
else
{
(*p_cb->p_cmd_cback)(p_cb->p_user,
p_cb->p_at_tbl[idx].command_id,
- arg_type, p_arg, int_arg);
+ arg_type, p_arg, p_end, int_arg);
}
}
/* else error */
@@ -216,8 +221,9 @@ void bta_ag_at_parse(tBTA_AG_AT_CB *p_cb, char *p_buf, UINT16 len)
(p_cb->p_cmd_buf[1] == 'T' || p_cb->p_cmd_buf[1] == 't'))
{
p_save = p_cb->p_cmd_buf;
+ char* p_end = p_cb->p_cmd_buf + p_cb->cmd_pos;
p_cb->p_cmd_buf += 2;
- bta_ag_process_at(p_cb);
+ bta_ag_process_at(p_cb, p_end);
p_cb->p_cmd_buf = p_save;
}
diff --git a/bta/ag/bta_ag_at.h b/bta/ag/bta_ag_at.h
index 4b78a33f3..b2dae6eb8 100644
--- a/bta/ag/bta_ag_at.h
+++ b/bta/ag/bta_ag_at.h
@@ -56,7 +56,7 @@ typedef struct
/* callback function executed when command is parsed */
typedef void (tBTA_AG_AT_CMD_CBACK)(void *p_user, UINT16 command_id, UINT8 arg_type,
- char *p_arg, INT16 int_arg);
+ char *p_arg, char *p_end, INT16 int_arg);
/* callback function executed to send "ERROR" result code */
typedef void (tBTA_AG_AT_ERR_CBACK)(void *p_user, BOOLEAN unknown, char *p_arg);
diff --git a/bta/ag/bta_ag_cmd.c b/bta/ag/bta_ag_cmd.c
index ebc4f4fbe..bbb4214fd 100644
--- a/bta/ag/bta_ag_cmd.c
+++ b/bta/ag/bta_ag_cmd.c
@@ -29,6 +29,7 @@
#include "bta_ag_int.h"
#include "bta_api.h"
#include "bta_sys.h"
+#include "log/log.h"
#include "bt_common.h"
#include "osi/include/log.h"
#include "port_api.h"
@@ -412,25 +413,24 @@ static void bta_ag_send_ind(tBTA_AG_SCB *p_scb, UINT16 id, UINT16 value, BOOLEAN
** Returns TRUE if parsed ok, FALSE otherwise.
**
*******************************************************************************/
-static BOOLEAN bta_ag_parse_cmer(char *p_s, BOOLEAN *p_enabled)
+static BOOLEAN bta_ag_parse_cmer(char *p_s, char *p_end, BOOLEAN *p_enabled)
{
INT16 n[4] = {-1, -1, -1, -1};
int i;
char *p;
- for (i = 0; i < 4; i++)
+ for (i = 0; i < 4; i++, p_s = p + 1)
{
/* skip to comma delimiter */
- for (p = p_s; *p != ',' && *p != 0; p++);
+ for (p = p_s; p < p_end && *p != ',' && *p != 0; p++);
/* get integer value */
+ if (p > p_end) {
+ android_errorWriteLog(0x534e4554, "112860487");
+ return false;
+ }
*p = 0;
n[i] = utl_str2int(p_s);
- p_s = p + 1;
- if (p_s == 0)
- {
- break;
- }
}
/* process values */
@@ -496,7 +496,7 @@ static UINT8 bta_ag_parse_chld(tBTA_AG_SCB *p_scb, char *p_s)
** Returns Returns bitmap of supported codecs.
**
*******************************************************************************/
-static tBTA_AG_PEER_CODEC bta_ag_parse_bac(tBTA_AG_SCB *p_scb, char *p_s)
+static tBTA_AG_PEER_CODEC bta_ag_parse_bac(tBTA_AG_SCB *p_scb, char *p_s, char *p_end)
{
tBTA_AG_PEER_CODEC retval = BTA_AG_CODEC_NONE;
UINT16 uuid_codec;
@@ -506,9 +506,13 @@ static tBTA_AG_PEER_CODEC bta_ag_parse_bac(tBTA_AG_SCB *p_scb, char *p_s)
while(p_s)
{
/* skip to comma delimiter */
- for(p = p_s; *p != ',' && *p != 0; p++);
+ for(p = p_s; p < p_end && *p != ',' && *p != 0; p++);
/* get integre value */
+ if (p > p_end) {
+ android_errorWriteLog(0x534e4554, "112860487");
+ break;
+ }
if (*p != 0)
{
*p = 0;
@@ -660,7 +664,7 @@ void bta_ag_send_call_inds(tBTA_AG_SCB *p_scb, tBTA_AG_RES result)
**
*******************************************************************************/
void bta_ag_at_hsp_cback(tBTA_AG_SCB *p_scb, UINT16 command_id, UINT8 arg_type,
- char *p_arg, INT16 int_arg)
+ char *p_arg, char *p_end, INT16 int_arg)
{
APPL_TRACE_DEBUG("AT cmd:%d arg_type:%d arg:%d arg:%s", command_id, arg_type,
int_arg, p_arg);
@@ -671,6 +675,13 @@ void bta_ag_at_hsp_cback(tBTA_AG_SCB *p_scb, UINT16 command_id, UINT8 arg_type,
val.hdr.handle = bta_ag_scb_to_idx(p_scb);
val.hdr.app_id = p_scb->app_id;
val.num = (UINT16) int_arg;
+
+ if ((p_end - p_arg + 1) >= (long)sizeof(val.str)) {
+ APPL_TRACE_ERROR("%s: p_arg is too long, send error and return", __func__);
+ bta_ag_send_error(p_scb, BTA_AG_ERR_TEXT_TOO_LONG);
+ android_errorWriteLog(0x534e4554, "112860487");
+ return;
+ }
strlcpy(val.str, p_arg, BTA_AG_AT_MAX_LEN);
/* call callback with event */
@@ -904,7 +915,7 @@ static bool bta_ag_parse_biev_response(tBTA_AG_SCB *p_scb, tBTA_AG_VAL *val)
**
*******************************************************************************/
void bta_ag_at_hfp_cback(tBTA_AG_SCB *p_scb, UINT16 cmd, UINT8 arg_type,
- char *p_arg, INT16 int_arg)
+ char *p_arg, char *p_end, INT16 int_arg)
{
tBTA_AG_VAL val;
tBTA_AG_SCB *ag_scb;
@@ -929,6 +940,13 @@ void bta_ag_at_hfp_cback(tBTA_AG_SCB *p_scb, UINT16 cmd, UINT8 arg_type,
val.hdr.status = BTA_AG_SUCCESS;
val.num = int_arg;
bdcpy(val.bd_addr, p_scb->peer_addr);
+
+ if ((p_end - p_arg + 1) >= (long)sizeof(val.str)) {
+ APPL_TRACE_ERROR("%s: p_arg is too long, send error and return", __func__);
+ bta_ag_send_error(p_scb, BTA_AG_ERR_TEXT_TOO_LONG);
+ android_errorWriteLog(0x534e4554, "112860487");
+ return;
+ }
strlcpy(val.str, p_arg, BTA_AG_AT_MAX_LEN);
/**
@@ -1115,7 +1133,7 @@ void bta_ag_at_hfp_cback(tBTA_AG_SCB *p_scb, UINT16 cmd, UINT8 arg_type,
case BTA_AG_LOCAL_EVT_CMER:
/* if parsed ok store setting, send OK */
- if (bta_ag_parse_cmer(p_arg, &p_scb->cmer_enabled))
+ if (bta_ag_parse_cmer(p_arg, p_end, &p_scb->cmer_enabled))
{
bta_ag_send_ok(p_scb);
@@ -1304,7 +1322,7 @@ void bta_ag_at_hfp_cback(tBTA_AG_SCB *p_scb, UINT16 cmd, UINT8 arg_type,
/* store available codecs from the peer */
if((p_scb->peer_features & BTA_AG_PEER_FEAT_CODEC) && (p_scb->features & BTA_AG_FEAT_CODEC))
{
- p_scb->peer_codecs = bta_ag_parse_bac(p_scb, p_arg);
+ p_scb->peer_codecs = bta_ag_parse_bac(p_scb, p_arg, p_end);
p_scb->codec_updated = TRUE;
if (p_scb->peer_codecs & BTA_AG_CODEC_MSBC)
diff --git a/bta/ag/bta_ag_int.h b/bta/ag/bta_ag_int.h
index c1e685f28..eac98c292 100644
--- a/bta/ag/bta_ag_int.h
+++ b/bta/ag/bta_ag_int.h
@@ -378,9 +378,9 @@ extern void bta_ag_sco_conn_rsp(tBTA_AG_SCB *p_scb, tBTM_ESCO_CONN_REQ_EVT_DATA
/* AT command functions */
extern void bta_ag_at_hsp_cback(tBTA_AG_SCB *p_scb, UINT16 cmd, UINT8 arg_type,
- char *p_arg, INT16 int_arg);
+ char *p_arg, char *p_end, INT16 int_arg);
extern void bta_ag_at_hfp_cback(tBTA_AG_SCB *p_scb, UINT16 cmd, UINT8 arg_type,
- char *p_arg, INT16 int_arg);
+ char *p_arg, char *p_end, INT16 int_arg);
extern void bta_ag_at_err_cback(tBTA_AG_SCB *p_scb, BOOLEAN unknown, char *p_arg);
extern BOOLEAN bta_ag_inband_enabled(tBTA_AG_SCB *p_scb);
extern void bta_ag_send_call_inds(tBTA_AG_SCB *p_scb, tBTA_AG_RES result);
diff --git a/bta/av/bta_av_act.c b/bta/av/bta_av_act.c
index 9cc802f0a..7154865c6 100644
--- a/bta/av/bta_av_act.c
+++ b/bta/av/bta_av_act.c
@@ -35,6 +35,7 @@
#include "bta_av_api.h"
#include "bta_av_int.h"
#include "l2c_api.h"
+#include "log/log.h"
#include "osi/include/list.h"
#include "osi/include/log.h"
#include "osi/include/osi.h"
@@ -800,11 +801,17 @@ tBTA_AV_EVT bta_av_proc_meta_cmd(tAVRC_RESPONSE *p_rc_rsp, tBTA_AV_RC_MSG *p_ms
case AVRC_PDU_GET_CAPABILITIES:
/* process GetCapabilities command without reporting the event to app */
evt = 0;
+ if (p_vendor->vendor_len != 5)
+ {
+ android_errorWriteLog(0x534e4554, "111893951");
+ p_rc_rsp->get_caps.status = AVRC_STS_INTERNAL_ERR;
+ break;
+ }
u8 = *(p_vendor->p_vendor_data + 4);
p = p_vendor->p_vendor_data + 2;
p_rc_rsp->get_caps.capability_id = u8;
BE_STREAM_TO_UINT16 (u16, p);
- if ((u16 != 1) || (p_vendor->vendor_len != 5))
+ if (u16 != 1)
{
p_rc_rsp->get_caps.status = AVRC_STS_INTERNAL_ERR;
}
diff --git a/bta/dm/bta_dm_act.c b/bta/dm/bta_dm_act.c
index 1bf741d92..7870a02b1 100644
--- a/bta/dm/bta_dm_act.c
+++ b/bta/dm/bta_dm_act.c
@@ -26,6 +26,7 @@
#define LOG_TAG "bt_bta_dm"
#include <assert.h>
+#include <cutils/log.h>
#include <string.h>
#include "bt_target.h"
@@ -49,6 +50,8 @@
#include "gap_api.h"
#endif
+#define BTA_MAX_SERVICES 32
+
static void bta_dm_inq_results_cb (tBTM_INQ_RESULTS *p_inq, UINT8 *p_eir);
static void bta_dm_inq_cmpl_cb (void * p_result);
static void bta_dm_service_search_remname_cback (BD_ADDR bd_addr, DEV_CLASS dc, BD_NAME bd_name);
@@ -1601,7 +1604,7 @@ void bta_dm_sdp_result (tBTA_DM_MSG *p_data)
#endif
UINT32 num_uuids = 0;
- UINT8 uuid_list[32][MAX_UUID_SIZE]; // assuming a max of 32 services
+ UINT8 uuid_list[BTA_MAX_SERVICES][MAX_UUID_SIZE]; // assuming a max of 32 services
if((p_data->sdp_event.sdp_result == SDP_SUCCESS)
|| (p_data->sdp_event.sdp_result == SDP_NO_RECS_MATCH)
@@ -1679,8 +1682,12 @@ void bta_dm_sdp_result (tBTA_DM_MSG *p_data)
(tBTA_SERVICE_MASK)(BTA_SERVICE_ID_TO_SERVICE_MASK(bta_dm_search_cb.service_index-1));
tmp_svc = bta_service_id_to_uuid_lkup_tbl[bta_dm_search_cb.service_index-1];
/* Add to the list of UUIDs */
- sdpu_uuid16_to_uuid128(tmp_svc, uuid_list[num_uuids]);
- num_uuids++;
+ if (num_uuids < BTA_MAX_SERVICES) {
+ sdpu_uuid16_to_uuid128(tmp_svc, uuid_list[num_uuids]);
+ num_uuids++;
+ } else {
+ android_errorWriteLog(0x534e4554, "74016921");
+ }
}
}
}
@@ -1719,8 +1726,12 @@ void bta_dm_sdp_result (tBTA_DM_MSG *p_data)
{
if (SDP_FindServiceUUIDInRec_128bit(p_sdp_rec, &temp_uuid))
{
- memcpy(uuid_list[num_uuids], temp_uuid.uu.uuid128, MAX_UUID_SIZE);
- num_uuids++;
+ if (num_uuids < BTA_MAX_SERVICES) {
+ memcpy(uuid_list[num_uuids], temp_uuid.uu.uuid128, MAX_UUID_SIZE);
+ num_uuids++;
+ } else {
+ android_errorWriteLog(0x534e4554, "74016921");
+ }
}
}
} while (p_sdp_rec);
@@ -3322,12 +3333,16 @@ void bta_dm_acl_change(tBTA_DM_MSG *p_data)
}
if (conn.link_down.is_removed)
{
- BTM_SecDeleteDevice(p_bda);
+ // p_bda points to security record, which is removed in
+ // BTM_SecDeleteDevice.
+ BD_ADDR addr_copy;
+ memcpy(addr_copy, p_bda, BD_ADDR_LEN);
+ BTM_SecDeleteDevice(addr_copy);
#if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE)
/* need to remove all pending background connection */
- BTA_GATTC_CancelOpen(0, p_bda, FALSE);
+ BTA_GATTC_CancelOpen(0, addr_copy, FALSE);
/* remove all cached GATT information */
- BTA_GATTC_Refresh(p_bda);
+ BTA_GATTC_Refresh(addr_copy);
#endif
}
diff --git a/bta/gatt/bta_gattc_cache.c b/bta/gatt/bta_gattc_cache.c
index 63c424696..45d258824 100644
--- a/bta/gatt/bta_gattc_cache.c
+++ b/bta/gatt/bta_gattc_cache.c
@@ -1551,7 +1551,7 @@ bool bta_gattc_cache_load(tBTA_GATTC_CLCB *p_clcb)
attr = osi_malloc(sizeof(tBTA_GATTC_NV_ATTR) * num_attr);
- if (fread(attr, sizeof(tBTA_GATTC_NV_ATTR), 0xFF, fd) != num_attr) {
+ if (fread(attr, sizeof(tBTA_GATTC_NV_ATTR), num_attr, fd) != num_attr) {
APPL_TRACE_ERROR("%s: can't read GATT attributes: %s", __func__, fname);
goto done;
}
diff --git a/bta/hh/bta_hh_act.c b/bta/hh/bta_hh_act.c
index f799e67e4..7d0e5bd0b 100644
--- a/bta/hh/bta_hh_act.c
+++ b/bta/hh/bta_hh_act.c
@@ -26,6 +26,7 @@
#if defined(BTA_HH_INCLUDED) && (BTA_HH_INCLUDED == TRUE)
+#include <log/log.h>
#include <string.h>
#include "bta_sys.h"
@@ -764,6 +765,12 @@ void bta_hh_ctrl_dat_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA * p_data)
APPL_TRACE_DEBUG("Ctrl DATA received w4: event[%s]",
bta_hh_get_w4_event(p_cb->w4_evt));
#endif
+ if (pdata->len == 0) {
+ android_errorWriteLog(0x534e4554, "116108738");
+ p_cb->w4_evt = 0;
+ osi_free_and_reset((void**)&pdata);
+ return;
+ }
hs_data.status = BTA_HH_OK;
hs_data.handle = p_cb->hid_handle;
diff --git a/bta/hl/bta_hl_main.c b/bta/hl/bta_hl_main.c
index b4d96cd8b..c4d9ed3dd 100644
--- a/bta/hl/bta_hl_main.c
+++ b/bta/hl/bta_hl_main.c
@@ -1564,7 +1564,6 @@ static void bta_hl_sdp_query_results(tBTA_HL_CB *p_cb, tBTA_HL_DATA *p_data)
tBTA_HL_MCL_CB *p_mcb = BTA_HL_GET_MCL_CB_PTR( app_idx, mcl_idx);
tBTA_HL_SDP *p_sdp=NULL;
UINT16 event;
- BOOLEAN release_sdp_buf=FALSE;
UNUSED(p_cb);
event = p_data->hdr.event;
@@ -1572,7 +1571,6 @@ static void bta_hl_sdp_query_results(tBTA_HL_CB *p_cb, tBTA_HL_DATA *p_data)
if (event == BTA_HL_SDP_QUERY_OK_EVT) {
p_sdp = (tBTA_HL_SDP *)osi_malloc(sizeof(tBTA_HL_SDP));
memcpy(p_sdp, &p_mcb->sdp, sizeof(tBTA_HL_SDP));
- release_sdp_buf = TRUE;
} else {
status = BTA_HL_STATUS_SDP_FAIL;
}
@@ -1589,9 +1587,6 @@ static void bta_hl_sdp_query_results(tBTA_HL_CB *p_cb, tBTA_HL_DATA *p_data)
p_mcb->bd_addr,p_sdp,status);
p_acb->p_cback(BTA_HL_SDP_QUERY_CFM_EVT,(tBTA_HL *) &evt_data );
- if (release_sdp_buf)
- osi_free_and_reset((void **)&p_sdp);
-
if (p_data->cch_sdp.release_mcl_cb) {
memset(p_mcb, 0, sizeof(tBTA_HL_MCL_CB));
} else {
diff --git a/bta/pan/bta_pan_act.c b/bta/pan/bta_pan_act.c
index 199547817..4367fce68 100644
--- a/bta/pan/bta_pan_act.c
+++ b/bta/pan/bta_pan_act.c
@@ -26,6 +26,8 @@
#if defined(PAN_INCLUDED) && (PAN_INCLUDED == TRUE)
+#include <cutils/log.h>
+
#include "bta_api.h"
#include "bta_sys.h"
#include "bt_common.h"
@@ -171,20 +173,25 @@ static void bta_pan_data_flow_cb(UINT16 handle, tPAN_RESULT result)
static void bta_pan_data_buf_ind_cback(UINT16 handle, BD_ADDR src, BD_ADDR dst, UINT16 protocol, BT_HDR *p_buf,
BOOLEAN ext, BOOLEAN forward)
{
- tBTA_PAN_SCB *p_scb;
- BT_HDR *p_new_buf;
-
- if (sizeof(tBTA_PAN_DATA_PARAMS) > p_buf->offset) {
- /* offset smaller than data structure in front of actual data */
- p_new_buf = (BT_HDR *)osi_malloc(PAN_BUF_SIZE);
- memcpy((UINT8 *)(p_new_buf + 1) + sizeof(tBTA_PAN_DATA_PARAMS),
- (UINT8 *)(p_buf + 1) + p_buf->offset, p_buf->len);
- p_new_buf->len = p_buf->len;
- p_new_buf->offset = sizeof(tBTA_PAN_DATA_PARAMS);
- osi_free(p_buf);
- } else {
- p_new_buf = p_buf;
+ tBTA_PAN_SCB* p_scb = bta_pan_scb_by_handle(handle);
+ if (p_scb == NULL) {
+ return;
+ }
+
+ if (sizeof(BT_HDR) + sizeof(tBTA_PAN_DATA_PARAMS) + p_buf->len >
+ PAN_BUF_SIZE) {
+ android_errorWriteLog(0x534e4554, "63146237");
+ APPL_TRACE_ERROR("%s: received buffer length too large: %d", __func__,
+ p_buf->len);
+ return;
}
+
+ BT_HDR* p_new_buf = (BT_HDR*)osi_malloc(PAN_BUF_SIZE);
+ memcpy((uint8_t*)(p_new_buf + 1) + sizeof(tBTA_PAN_DATA_PARAMS),
+ (uint8_t*)(p_buf + 1) + p_buf->offset, p_buf->len);
+ p_new_buf->len = p_buf->len;
+ p_new_buf->offset = sizeof(tBTA_PAN_DATA_PARAMS);
+
/* copy params into the space before the data */
bdcpy(((tBTA_PAN_DATA_PARAMS *)p_new_buf)->src, src);
bdcpy(((tBTA_PAN_DATA_PARAMS *)p_new_buf)->dst, dst);
@@ -192,11 +199,6 @@ static void bta_pan_data_buf_ind_cback(UINT16 handle, BD_ADDR src, BD_ADDR dst,
((tBTA_PAN_DATA_PARAMS *)p_new_buf)->ext = ext;
((tBTA_PAN_DATA_PARAMS *)p_new_buf)->forward = forward;
- if ((p_scb = bta_pan_scb_by_handle(handle)) == NULL) {
- osi_free(p_new_buf);
- return;
- }
-
fixed_queue_enqueue(p_scb->data_queue, p_new_buf);
BT_HDR *p_event = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
p_event->layer_specific = handle;
diff --git a/btif/src/btif_hf.c b/btif/src/btif_hf.c
index 6abf09901..9d963d1de 100644
--- a/btif/src/btif_hf.c
+++ b/btif/src/btif_hf.c
@@ -33,6 +33,7 @@
#include <hardware/bluetooth.h>
#include <hardware/bt_hf.h>
+#include <log/log.h>
#include "bta_ag_api.h"
#include "btcore/include/bdaddr.h"
@@ -1261,13 +1262,20 @@ static bt_status_t clcc_response(int index, bthf_call_direction_t dir,
index, dir, state, mode, number, type);
xx = sprintf (ag_res.str, "%d,%d,%d,%d,%d",
index, dir, state, mode, mpty);
+ char number_copy[sizeof(ag_res.str)];
+ // 9 = [,]["][+]["][,][3_digit_type][null_terminator]
+ int max_number_len = sizeof(ag_res.str) - xx - 9;
+ int number_len = snprintf(number_copy, max_number_len, "%s", number);
+ if (number_len >= max_number_len) {
+ android_errorWriteLog(0x534e4554, "79266386");
+ }
if (number)
{
if ((type == BTHF_CALL_ADDRTYPE_INTERNATIONAL) && (*number != '+'))
- sprintf (&ag_res.str[xx], ",\"+%s\",%d", number, type);
+ sprintf (&ag_res.str[xx], ",\"+%s\",%d", number_copy, type);
else
- sprintf (&ag_res.str[xx], ",\"%s\",%d", number, type);
+ sprintf (&ag_res.str[xx], ",\"%s\",%d", number_copy, type);
}
}
BTA_AgResult (btif_hf_cb[idx].handle, BTA_AG_CLCC_RES, &ag_res);
@@ -1420,10 +1428,17 @@ static bt_status_t phone_state_change(int num_active, int num_held, bthf_call_st
if (number)
{
int xx = 0;
+ char number_copy[sizeof(ag_res.str)];
+ // 8 = ["][+]["][,][3_digit_type][null_terminator]
+ int max_number_len = sizeof(ag_res.str) - xx - 8;
+ int number_len = snprintf(number_copy, max_number_len, "%s", number);
+ if (number_len >= max_number_len) {
+ android_errorWriteLog(0x534e4554, "79431031");
+ }
if ((type == BTHF_CALL_ADDRTYPE_INTERNATIONAL) && (*number != '+'))
- xx = sprintf (ag_res.str, "\"+%s\"", number);
+ xx = sprintf (ag_res.str, "\"+%s\"", number_copy);
else
- xx = sprintf (ag_res.str, "\"%s\"", number);
+ xx = sprintf (ag_res.str, "\"%s\"", number_copy);
ag_res.num = type;
if (res == BTA_AG_CALL_WAIT_RES)
diff --git a/btif/src/btif_hl.c b/btif/src/btif_hl.c
index eec9d3449..f0e2a879f 100644
--- a/btif/src/btif_hl.c
+++ b/btif/src/btif_hl.c
@@ -2333,6 +2333,11 @@ static BOOLEAN btif_hl_proc_sdp_query_cfm(tBTA_HL *p_data){
}
}
}
+
+ // this was allocated in bta_hl_sdp_query_results
+ osi_free_and_reset((void**)&p_data->sdp_query_cfm.p_sdp);
+
+
return status;
}
diff --git a/btif/src/btif_rc.c b/btif/src/btif_rc.c
index 6572fd74e..133277a35 100644
--- a/btif/src/btif_rc.c
+++ b/btif/src/btif_rc.c
@@ -42,6 +42,7 @@
#include "btif_util.h"
#include "bt_common.h"
#include "device/include/interop.h"
+#include "log/log.h"
#include "uinput.h"
#include "bdaddr.h"
#include "osi/include/list.h"
@@ -2764,6 +2765,12 @@ static void handle_app_cur_val_response (tBTA_AV_META_MSG *pmeta_msg, tAVRC_GET_
bdcpy(rc_addr.address, btif_rc_cb.rc_addr);
app_settings.num_attr = p_rsp->num_val;
+
+ if (app_settings.num_attr > BTRC_MAX_APP_SETTINGS) {
+ android_errorWriteLog(0x534e4554, "73824150");
+ app_settings.num_attr = BTRC_MAX_APP_SETTINGS;
+ }
+
for (xx = 0; xx < app_settings.num_attr; xx++)
{
app_settings.attr_ids[xx] = p_rsp->p_vals[xx].attr_id;
diff --git a/btif/src/btif_sdp_server.c b/btif/src/btif_sdp_server.c
index d02dfa0b8..90d74cf53 100644
--- a/btif/src/btif_sdp_server.c
+++ b/btif/src/btif_sdp_server.c
@@ -215,7 +215,8 @@ static int alloc_sdp_slot(bluetooth_sdp_record* in_record) {
static int free_sdp_slot(int id) {
int handle = -1;
bluetooth_sdp_record* record = NULL;
- if(id >= MAX_SDP_SLOTS) {
+ if(id < 0 || id >= MAX_SDP_SLOTS) {
+ android_errorWriteLog(0x534e4554, "37502513");
APPL_TRACE_ERROR("%s() failed - id %d is invalid", __func__, id);
return handle;
}
diff --git a/btif/src/btif_storage.c b/btif/src/btif_storage.c
index 83dcc8c47..670af4f4d 100644
--- a/btif/src/btif_storage.c
+++ b/btif/src/btif_storage.c
@@ -35,6 +35,7 @@
#include <alloca.h>
#include <assert.h>
#include <ctype.h>
+#include <log/log.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
@@ -49,6 +50,7 @@
#include "osi/include/allocator.h"
#include "osi/include/compat.h"
#include "osi/include/config.h"
+#include "osi/include/list.h"
#include "osi/include/log.h"
#include "osi/include/osi.h"
@@ -229,6 +231,10 @@ static int prop2cfg(bt_bdaddr_t *remote_bd_addr, bt_property_t *prop)
bt_uuid_t *p_uuid = (bt_uuid_t*)prop->val + i;
memset(buf, 0, sizeof(buf));
uuid_to_string_legacy(p_uuid, buf);
+ if (strlen(value) + strlen(buf) + 1 > (int) sizeof(value) - 1) {
+ android_errorWriteLog(0x534e4554, "73963551");
+ return FALSE;
+ }
strcat(value, buf);
//strcat(value, ";");
strcat(value, " ");
@@ -829,6 +835,47 @@ bt_status_t btif_storage_remove_bonded_device(bt_bdaddr_t *remote_bd_addr)
}
+/* Some devices hardcode sample LTK value from spec, instead of generating one.
+ * Treat such devices as insecure, and remove such bonds when bluetooth restarts.
+ * Removing them after disconnection is handled separately.
+ *
+ * We still allow such devices to bond in order to give the user a chance to update
+ * firmware.
+ */
+static void remove_devices_with_sample_ltk() {
+ list_t *bad_ltk = list_new(osi_free);
+
+ for (const btif_config_section_iter_t *iter = btif_config_section_begin(); iter != btif_config_section_end(); iter = btif_config_section_next(iter)) {
+ const char *name = btif_config_section_name(iter);
+ if (!string_is_bdaddr(name)) {
+ continue;
+ }
+
+ bt_bdaddr_t *bda = osi_malloc(sizeof(bt_bdaddr_t));
+ string_to_bdaddr(name, bda);
+
+ tBTA_LE_KEY_VALUE key;
+ memset(&key, 0, sizeof(key));
+
+ if (btif_storage_get_ble_bonding_key(bda, BTIF_DM_LE_KEY_PENC, (char*)&key, sizeof(tBTM_LE_PENC_KEYS)) ==
+ BT_STATUS_SUCCESS) {
+ if (is_sample_ltk(key.penc_key.ltk)) {
+ list_append(bad_ltk, (void*)bda);
+ }
+ }
+ }
+
+ for (list_node_t *sn = list_begin(bad_ltk); sn != list_end(bad_ltk); sn = list_next(sn)) {
+ android_errorWriteLog(0x534e4554, "128437297");
+ BTIF_TRACE_ERROR("%s: removing bond to device using test TLK", __func__);
+
+ bt_bdaddr_t *bda = (bt_bdaddr_t*)list_node(sn);
+ btif_storage_remove_bonded_device(bda);
+ }
+
+ list_free(bad_ltk);
+}
+
/*******************************************************************************
**
** Function btif_storage_load_bonded_devices
@@ -855,6 +902,8 @@ bt_status_t btif_storage_load_bonded_devices(void)
bt_uuid_t local_uuids[BT_MAX_NUM_UUIDS];
bt_uuid_t remote_uuids[BT_MAX_NUM_UUIDS];
+ remove_devices_with_sample_ltk();
+
btif_in_fetch_bonded_devices(&bonded_devices, 1);
/* Now send the adapter_properties_cb with all adapter_properties */
diff --git a/device/src/controller.c b/device/src/controller.c
index 4440ea55a..23799d803 100644
--- a/device/src/controller.c
+++ b/device/src/controller.c
@@ -252,6 +252,8 @@ static future_t *start_up(void) {
&number_of_local_supported_codecs, local_supported_codecs);
}
+ assert(HCI_READ_ENCR_KEY_SIZE_SUPPORTED(supported_commands));
+
readable = true;
return future_new_immediate(FUTURE_SUCCESS);
}
diff --git a/osi/src/alarm.c b/osi/src/alarm.c
index 69ded69e4..5f9e42ce3 100644
--- a/osi/src/alarm.c
+++ b/osi/src/alarm.c
@@ -64,7 +64,6 @@ typedef struct {
size_t rescheduled_count;
size_t total_updates;
period_ms_t last_update_ms;
- stat_t callback_execution;
stat_t overdue_scheduling;
stat_t premature_scheduling;
} alarm_stats_t;
@@ -136,8 +135,7 @@ static void callback_dispatch(void *context);
static bool timer_create_internal(const clockid_t clock_id, timer_t *timer);
static void update_scheduling_stats(alarm_stats_t *stats,
period_ms_t now_ms,
- period_ms_t deadline_ms,
- period_ms_t execution_delta_ms);
+ period_ms_t deadline_ms);
static void update_stat(stat_t *stat, period_ms_t delta)
{
@@ -614,14 +612,12 @@ static void alarm_queue_ready(fixed_queue_t *queue,
pthread_mutex_lock(&alarm->callback_lock);
pthread_mutex_unlock(&monitor);
- period_ms_t t0 = now();
- callback(data);
- period_ms_t t1 = now();
-
// Update the statistics
- assert(t1 >= t0);
- period_ms_t delta = t1 - t0;
- update_scheduling_stats(&alarm->stats, t0, deadline, delta);
+ update_scheduling_stats(&alarm->stats, now(), deadline);
+
+ // NOTE: Do NOT access "alarm" after the callback, as a safety precaution
+ // in case the callback itself deleted the alarm.
+ callback(data);
pthread_mutex_unlock(&alarm->callback_lock);
}
@@ -695,14 +691,11 @@ static bool timer_create_internal(const clockid_t clock_id, timer_t *timer) {
static void update_scheduling_stats(alarm_stats_t *stats,
period_ms_t now_ms,
- period_ms_t deadline_ms,
- period_ms_t execution_delta_ms)
+ period_ms_t deadline_ms)
{
stats->total_updates++;
stats->last_update_ms = now_ms;
- update_stat(&stats->callback_execution, execution_delta_ms);
-
if (deadline_ms < now_ms) {
// Overdue scheduling
period_ms_t delta_ms = now_ms - deadline_ms;
@@ -755,7 +748,7 @@ void alarm_debug_dump(int fd)
dprintf(fd, "%-51s: %zu / %zu / %zu / %zu\n",
" Action counts (sched/resched/exec/cancel)",
stats->scheduled_count, stats->rescheduled_count,
- stats->callback_execution.count, stats->canceled_count);
+ stats->total_updates, stats->canceled_count);
dprintf(fd, "%-51s: %zu / %zu\n",
" Deviation counts (overdue/premature)",
@@ -768,9 +761,6 @@ void alarm_debug_dump(int fd)
(unsigned long long) alarm->period,
(long long)(alarm->deadline - just_now));
- dump_stat(fd, &stats->callback_execution,
- " Callback execution time in ms (total/max/avg)");
-
dump_stat(fd, &stats->overdue_scheduling,
" Overdue scheduling time in ms (total/max/avg)");
diff --git a/osi/src/config.c b/osi/src/config.c
index 345f907d5..b38977f07 100644
--- a/osi/src/config.c
+++ b/osi/src/config.c
@@ -34,6 +34,7 @@
#include "osi/include/allocator.h"
#include "osi/include/list.h"
#include "osi/include/log.h"
+#include "log/log.h"
typedef struct {
char *key;
@@ -216,16 +217,37 @@ void config_set_string(config_t *config, const char *section, const char *key, c
list_append(config->sections, sec);
}
+ char *value_string = (char *)value;
+ char *value_no_newline;
+ char *newline = strstr(value_string, "\n");
+ if (newline) {
+ android_errorWriteLog(0x534e4554, "70808273");
+ size_t newline_pos = newline - value_string;
+ value_no_newline = osi_strndup(value_string, newline_pos);
+ if (!value_no_newline) {
+ LOG_ERROR(LOG_TAG,"%s: Unable to allocate memory for value_no_newline", __func__);
+ return;
+ }
+ } else {
+ value_no_newline = value_string;
+ }
+
for (const list_node_t *node = list_begin(sec->entries); node != list_end(sec->entries); node = list_next(node)) {
entry_t *entry = list_node(node);
if (!strcmp(entry->key, key)) {
osi_free(entry->value);
- entry->value = osi_strdup(value);
+ entry->value = osi_strdup(value_no_newline);
+ if (newline) {
+ osi_free(value_no_newline);
+ }
return;
}
}
- entry_t *entry = entry_new(key, value);
+ entry_t *entry = entry_new(key, value_no_newline);
+ if (newline) {
+ osi_free(value_no_newline);
+ }
list_append(sec->entries, entry);
}
diff --git a/stack/avdt/avdt_api.c b/stack/avdt/avdt_api.c
index 98ef5f755..52010541d 100644
--- a/stack/avdt/avdt_api.c
+++ b/stack/avdt/avdt_api.c
@@ -1208,7 +1208,7 @@ UINT16 AVDT_SendReport(UINT8 handle, AVDT_REPORT_TYPE type,
/* build SR - assume fit in one packet */
p_tbl = avdt_ad_tc_tbl_by_type(AVDT_CHAN_REPORT, p_scb->p_ccb, p_scb);
if (p_tbl->state == AVDT_AD_ST_OPEN) {
- BT_HDR *p_pkt = (BT_HDR *)osi_malloc(p_tbl->peer_mtu);
+ BT_HDR *p_pkt = (BT_HDR *)osi_malloc(p_tbl->peer_mtu + sizeof(BT_HDR));
p_pkt->offset = L2CAP_MIN_OFFSET;
p = (UINT8 *)(p_pkt + 1) + p_pkt->offset;
diff --git a/stack/avdt/avdt_msg.c b/stack/avdt/avdt_msg.c
index adc1ae731..91a58403e 100644
--- a/stack/avdt/avdt_msg.c
+++ b/stack/avdt/avdt_msg.c
@@ -26,6 +26,7 @@
*
******************************************************************************/
+#include <log/log.h>
#include <string.h>
#include "bt_types.h"
#include "bt_target.h"
@@ -673,6 +674,12 @@ static UINT8 avdt_msg_prs_cfg(tAVDT_CFG *p_cfg, UINT8 *p, UINT16 len, UINT8* p_e
case AVDT_CAT_PROTECT:
p_cfg->psc_mask &= ~AVDT_PSC_PROTECT;
+ if (p + elem_len > p_end)
+ {
+ err = AVDT_ERR_LENGTH;
+ android_errorWriteLog(0x534e4554, "78288378");
+ break;
+ }
if ((elem_len + protect_offset) < AVDT_PROTECT_SIZE)
{
p_cfg->num_protect++;
@@ -747,6 +754,12 @@ static UINT8 avdt_msg_prs_cfg(tAVDT_CFG *p_cfg, UINT8 *p, UINT16 len, UINT8* p_e
{
tmp = AVDT_CODEC_SIZE - 1;
}
+ if (p + tmp > p_end)
+ {
+ err = AVDT_ERR_LENGTH;
+ android_errorWriteLog(0x534e4554, "78288378");
+ break;
+ }
p_cfg->num_codec++;
p_cfg->codec_info[0] = elem_len;
memcpy(&p_cfg->codec_info[1], p, tmp);
diff --git a/stack/avdt/avdt_scb_act.c b/stack/avdt/avdt_scb_act.c
index ed0b67536..350f28e41 100644
--- a/stack/avdt/avdt_scb_act.c
+++ b/stack/avdt/avdt_scb_act.c
@@ -23,6 +23,7 @@
*
******************************************************************************/
+#include <cutils/log.h>
#include <string.h>
#include "bt_types.h"
#include "bt_target.h"
@@ -256,10 +257,14 @@ void avdt_scb_hdl_pkt_no_frag(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
UINT16 offset;
UINT16 ex_len;
UINT8 pad_len = 0;
+ UINT16 len = p_data->p_pkt->len;
p = p_start = (UINT8 *)(p_data->p_pkt + 1) + p_data->p_pkt->offset;
/* parse media packet header */
+ offset = 12;
+ // AVDT_MSG_PRS_OCTET1(1) + AVDT_MSG_PRS_M_PT(1) + UINT16(2) + UINT32(4) + 4
+ if (offset > len) goto length_error;
AVDT_MSG_PRS_OCTET1(p, o_v, o_p, o_x, o_cc);
AVDT_MSG_PRS_M_PT(p, m_pt, marker);
BE_STREAM_TO_UINT16(seq, p);
@@ -269,19 +274,20 @@ void avdt_scb_hdl_pkt_no_frag(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
UNUSED(o_v);
/* skip over any csrc's in packet */
+ offset += o_cc * 4;
p += o_cc * 4;
/* check for and skip over extension header */
if (o_x)
{
+ offset += 4;
+ if (offset > len) goto length_error;
p += 2;
BE_STREAM_TO_UINT16(ex_len, p);
+ offset += ex_len * 4;
p += ex_len * 4;
}
- /* save our new offset */
- offset = (UINT16) (p - p_start);
-
/* adjust length for any padding at end of packet */
if (o_p)
{
@@ -325,6 +331,13 @@ void avdt_scb_hdl_pkt_no_frag(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
osi_free_and_reset((void **)&p_data->p_pkt);
}
}
+ return;
+
+length_error:
+ android_errorWriteLog(0x534e4554, "111450156");
+ AVDT_TRACE_WARNING("%s: hdl packet length %d too short: must be at least %d",
+ __func__, len, offset);
+ osi_free_and_reset((void**)&p_data->p_pkt);
}
#if AVDT_REPORTING == TRUE
@@ -343,14 +356,24 @@ UINT8 * avdt_scb_hdl_report(tAVDT_SCB *p_scb, UINT8 *p, UINT16 len)
UINT8 *p_start = p;
UINT32 ssrc;
UINT8 o_v, o_p, o_cc;
+ UINT16 min_len = 0;
AVDT_REPORT_TYPE pt;
tAVDT_REPORT_DATA report, *p_rpt;
+ UINT8 sdes_type;
AVDT_TRACE_DEBUG( "avdt_scb_hdl_report");
if(p_scb->cs.p_report_cback)
{
p_rpt = &report;
/* parse report packet header */
+ min_len += 8;
+ if (min_len > len) {
+ android_errorWriteLog(0x534e4554, "111450156");
+ AVDT_TRACE_WARNING(
+ "%s: hdl packet length %d too short: must be at least %d", __func__,
+ len, min_len);
+ goto avdt_scb_hdl_report_exit;
+ }
AVDT_MSG_PRS_RPT_OCTET1(p, o_v, o_p, o_cc);
pt = *p++;
p += 2;
@@ -362,6 +385,14 @@ UINT8 * avdt_scb_hdl_report(tAVDT_SCB *p_scb, UINT8 *p, UINT16 len)
switch(pt)
{
case AVDT_RTCP_PT_SR: /* the packet type - SR (Sender Report) */
+ min_len += 20;
+ if (min_len > len) {
+ android_errorWriteLog(0x534e4554, "111450156");
+ AVDT_TRACE_WARNING(
+ "%s: hdl packet length %d too short: must be at least %d",
+ __func__, len, min_len);
+ goto avdt_scb_hdl_report_exit;
+ }
BE_STREAM_TO_UINT32(report.sr.ntp_sec, p);
BE_STREAM_TO_UINT32(report.sr.ntp_frac, p);
BE_STREAM_TO_UINT32(report.sr.rtp_time, p);
@@ -370,6 +401,14 @@ UINT8 * avdt_scb_hdl_report(tAVDT_SCB *p_scb, UINT8 *p, UINT16 len)
break;
case AVDT_RTCP_PT_RR: /* the packet type - RR (Receiver Report) */
+ min_len += 20;
+ if (min_len > len) {
+ android_errorWriteLog(0x534e4554, "111450156");
+ AVDT_TRACE_WARNING(
+ "%s: hdl packet length %d too short: must be at least %d",
+ __func__, len, min_len);
+ goto avdt_scb_hdl_report_exit;
+ }
report.rr.frag_lost = *p;
BE_STREAM_TO_UINT32(report.rr.packet_lost, p);
report.rr.packet_lost &= 0xFFFFFF;
@@ -380,12 +419,42 @@ UINT8 * avdt_scb_hdl_report(tAVDT_SCB *p_scb, UINT8 *p, UINT16 len)
break;
case AVDT_RTCP_PT_SDES: /* the packet type - SDES (Source Description) */
- if(*p == AVDT_RTCP_SDES_CNAME)
+ min_len += 1;
+ if (min_len > len) {
+ android_errorWriteLog(0x534e4554, "111450156");
+ AVDT_TRACE_WARNING(