summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTedd Ho-Jeong An <tedd.an@intel.com>2021-12-08 14:39:21 -0800
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2021-12-08 16:56:18 -0800
commit9968b0b66abf6dec89f68447d7158608c105c17c (patch)
treef886c75016fad7ec76b7f1395743a8fc19b4dd6d
parenta11eea9259212fca4d028746c3107258021a8554 (diff)
downloadbluez-9968b0b66abf6dec89f68447d7158608c105c17c.tar.gz
tools/btgatt-server: Replace random number generation function
This patch replaces the rand() function to the getrandom() syscall. It was reported by the Coverity scan rand() should not be used for security-related applications, because linear congruential algorithms are too easy to break
-rw-r--r--tools/btgatt-server.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/tools/btgatt-server.c b/tools/btgatt-server.c
index 000145a3d..15d49a464 100644
--- a/tools/btgatt-server.c
+++ b/tools/btgatt-server.c
@@ -20,6 +20,7 @@
#include <getopt.h>
#include <unistd.h>
#include <errno.h>
+#include <sys/random.h>
#include "lib/bluetooth.h"
#include "lib/hci.h"
@@ -284,9 +285,13 @@ static bool hr_msrmt_cb(void *user_data)
uint16_t len = 2;
uint8_t pdu[4];
uint32_t cur_ee;
+ uint32_t val;
+
+ if (getrandom(&val, sizeof(val), 0) < 0)
+ return false;
pdu[0] = 0x06;
- pdu[1] = 90 + (rand() % 40);
+ pdu[1] = 90 + (val % 40);
if (expended_present) {
pdu[0] |= 0x08;