[v6,06/11] bluetooth: Add missing validations for SBC codec parameters

Submitted by Pali Rohár on Feb. 3, 2019, 2:15 p.m.

Details

Message ID 20190203141518.28510-7-pali.rohar@gmail.com
State Accepted
Commit 745c161cc0316eefbac6ee8240da42ae048cfded
Headers show
Series "New API for Bluetooth A2DP codecs" ( rev: 31 30 29 28 27 26 25 24 23 22 21 20 ) in PulseAudio

Not browsing as part of any series.

Commit Message

Pali Rohár Feb. 3, 2019, 2:15 p.m.
---
 src/modules/bluetooth/a2dp-codec-sbc.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/src/modules/bluetooth/a2dp-codec-sbc.c b/src/modules/bluetooth/a2dp-codec-sbc.c
index 3db827db3..170dfc39d 100644
--- a/src/modules/bluetooth/a2dp-codec-sbc.c
+++ b/src/modules/bluetooth/a2dp-codec-sbc.c
@@ -145,6 +145,11 @@  static bool validate_configuration(const uint8_t *config_buffer, uint8_t config_
         return false;
     }
 
+    if (config->min_bitpool > config->max_bitpool) {
+        pa_log_error("Invalid bitpool in configuration");
+        return false;
+    }
+
     return true;
 }
 
@@ -289,12 +294,18 @@  static uint8_t fill_preferred_configuration(const pa_sample_spec *default_sample
         config->allocation_method = SBC_ALLOCATION_LOUDNESS;
     else if (capabilities->allocation_method & SBC_ALLOCATION_SNR)
         config->allocation_method = SBC_ALLOCATION_SNR;
+    else {
+        pa_log_error("No supported allocation method");
+        return 0;
+    }
 
     config->min_bitpool = (uint8_t) PA_MAX(SBC_MIN_BITPOOL, capabilities->min_bitpool);
     config->max_bitpool = (uint8_t) PA_MIN(default_bitpool(config->frequency, config->channel_mode), capabilities->max_bitpool);
 
-    if (config->min_bitpool > config->max_bitpool)
+    if (config->min_bitpool > config->max_bitpool) {
+        pa_log_error("No supported bitpool");
         return 0;
+    }
 
     return sizeof(*config);
 }