[1/8] bluetooth: ofono: Fix Coverity warning

Submitted by Peter Meerwald-Stadler on Sept. 6, 2017, 12:23 p.m.

Details

Message ID 1504700642-7253-2-git-send-email-pmeerw@pmeerw.net
State New
Headers show
Series "some Coverity and gcc-7 fixes" ( rev: 1 ) in PulseAudio

Not browsing as part of any series.

Commit Message

Peter Meerwald-Stadler Sept. 6, 2017, 12:23 p.m.
Dereference before null check

Coverity ID: #1454315

Signed-off-by: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
---
 src/modules/bluetooth/backend-ofono.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/modules/bluetooth/backend-ofono.c b/src/modules/bluetooth/backend-ofono.c
index 2c51497..782b353 100644
--- a/src/modules/bluetooth/backend-ofono.c
+++ b/src/modules/bluetooth/backend-ofono.c
@@ -545,11 +545,11 @@  static DBusMessage *hf_audio_agent_new_connection(DBusConnection *c, DBusMessage
         return r;
     }
 
-    card = pa_hashmap_get(backend->cards, path);
+    pa_assert_se(card = pa_hashmap_get(backend->cards, path));
 
     card->connecting = false;
 
-    if (!card || codec != HFP_AUDIO_CODEC_CVSD || card->fd >= 0) {
+    if (codec != HFP_AUDIO_CODEC_CVSD || card->fd >= 0) {
         pa_log_warn("New audio connection invalid arguments (path=%s fd=%d, codec=%d)", path, fd, codec);
         pa_assert_se(r = dbus_message_new_error(m, "org.ofono.Error.InvalidArguments", "Invalid arguments in method call"));
         shutdown(fd, SHUT_RDWR);

Comments

On 06.09.2017 14:23, Peter Meerwald-Stadler wrote:
> Dereference before null check
>
> Coverity ID: #1454315
>
> Signed-off-by: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
> ---
>   src/modules/bluetooth/backend-ofono.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/src/modules/bluetooth/backend-ofono.c b/src/modules/bluetooth/backend-ofono.c
> index 2c51497..782b353 100644
> --- a/src/modules/bluetooth/backend-ofono.c
> +++ b/src/modules/bluetooth/backend-ofono.c
> @@ -545,11 +545,11 @@ static DBusMessage *hf_audio_agent_new_connection(DBusConnection *c, DBusMessage
>           return r;
>       }
>   
> -    card = pa_hashmap_get(backend->cards, path);
> +    pa_assert_se(card = pa_hashmap_get(backend->cards, path));
>   
>       card->connecting = false;
>   
> -    if (!card || codec != HFP_AUDIO_CODEC_CVSD || card->fd >= 0) {
> +    if (codec != HFP_AUDIO_CODEC_CVSD || card->fd >= 0) {
>           pa_log_warn("New audio connection invalid arguments (path=%s fd=%d, codec=%d)", path, fd, codec);
>           pa_assert_se(r = dbus_message_new_error(m, "org.ofono.Error.InvalidArguments", "Invalid arguments in method call"));
>           shutdown(fd, SHUT_RDWR);

Hi Peter,

wouldn't it be better to protect the access to card->connecting with an 
"if (card)"?
The new_connection function() is called when a device requests a 
connection and
I think PA should handle the case gracefully when an unknown device tries to
connect.

Regards
              Georg