Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/bta2dpd/bta2dpd Avoid potential undefined behavior ...



details:   https://anonhg.NetBSD.org/src/rev/939d6968c79b
branches:  trunk
changeset: 834052:939d6968c79b
user:      kamil <kamil%NetBSD.org@localhost>
date:      Wed Jul 25 19:03:50 2018 +0000

description:
Avoid potential undefined behavior in bta2dpd(8)

The operator >> causes implicit promotion to int.

There is need to cast the result back to uint8_t in order to save the
return value to a data undef a pointe of type uint8_t.

Requested by GCC when building with Undefined Behavior Sanitizer.

diffstat:

 usr.sbin/bta2dpd/bta2dpd/avdtp.c |  5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)

diffs (23 lines):

diff -r 668807fdcfd6 -r 939d6968c79b usr.sbin/bta2dpd/bta2dpd/avdtp.c
--- a/usr.sbin/bta2dpd/bta2dpd/avdtp.c  Wed Jul 25 15:35:27 2018 +0000
+++ b/usr.sbin/bta2dpd/bta2dpd/avdtp.c  Wed Jul 25 19:03:50 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: avdtp.c,v 1.1 2017/01/28 16:55:54 nat Exp $ */
+/* $NetBSD: avdtp.c,v 1.2 2018/07/25 19:03:50 kamil Exp $ */
 
 /*-
  * Copyright (c) 2015 - 2016 Nathanial Sloss <nathanialsloss%yahoo.com.au@localhost>
@@ -89,7 +89,7 @@
        if (len < AVDTP_LEN_SUCCESS)
                return ENOMEM;
 
-       *trans = (buffer[0] & TRANSACTIONLABEL) >> TRANSACTIONLABEL_S;
+       *trans = (uint8_t)((buffer[0] & TRANSACTIONLABEL) >> TRANSACTIONLABEL_S);
        *signalId = buffer[1] & SIGNALID_MASK;
        if ((buffer[0] & MESSAGETYPE) == COMMAND) {
                if (datasize)
@@ -377,4 +377,3 @@
 auto_config_failed:
        return EINVAL;
 }
-



Home | Main Index | Thread Index | Old Index