Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fd6d05a3 authored by VenkatRaghavan VijayaRaghavan's avatar VenkatRaghavan VijayaRaghavan Committed by Andre Eisenbach
Browse files

Static code analysis cleanups and minor bug fixes

- Fix for initializing all the un-initialized variables
- Handling system call failure like socket,fcntl etc...
- In btpan_tap_close validate tap_if_down and close the socket.
- Invalid memset size, which could have potential memory issue
- Change -1 to INVALID_FD where appropriate

Bug: 19417758
Change-Id: Id31832f8678b2d72c80740c29b946a94e7ae0197
parent 6db0ee31
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -170,10 +170,10 @@ void bta_hh_disc_cmpl(void)

#if (BTA_HH_LE_INCLUDED == TRUE)
    bta_hh_le_deregister();
    return;
#endif

    UNUSED(status);
#else
    bta_hh_cleanup_disable(status);
#endif
}

/*******************************************************************************
@@ -189,7 +189,7 @@ static void bta_hh_sdp_cback(UINT16 result, UINT16 attr_mask,
                                  tHID_DEV_SDP_INFO *sdp_rec )
{
    tBTA_HH_DEV_CB     *p_cb = bta_hh_cb.p_cur;
    UINT8              hdl;
    UINT8              hdl = 0;
    tBTA_HH_STATUS    status = BTA_HH_ERR_SDP;

    /* make sure sdp succeeded and hh has not been disabled */
+3 −2
Original line number Diff line number Diff line
@@ -2321,7 +2321,8 @@ void bta_hh_le_write_char_descr_cmpl(tBTA_HH_DEV_CB *p_dev_cb, tBTA_HH_DATA *p_b
                        bta_hh_uuid_to_str(p_data->descr_type.uuid.uu.uuid16),
                        p_data->descr_type.uuid.uu.uuid16);
#else
        APPL_TRACE_ERROR("Unexpected write to (0x%04x)", p_data->descr_type.uuid.uu.uuid16);
            APPL_TRACE_ERROR("Unexpected write to (0x%04x)",
                        p_data->descr_type.uuid.uu.uuid16);
#endif
    }

+0 −2
Original line number Diff line number Diff line
@@ -938,11 +938,9 @@ static void bta_hl_api_cch_close(tBTA_HL_CB *p_cb, tBTA_HL_DATA *p_data)
                APPL_TRACE_ERROR("bta_hl_api_cch_close Null Callback");
            }
            break;

        default:
            APPL_TRACE_ERROR("status code=%d", status);
            break;

    }

}
+1 −1
Original line number Diff line number Diff line
@@ -2513,7 +2513,7 @@ bt_status_t btif_dm_get_adapter_property(bt_property_t *prop)
        case BT_PROPERTY_BDNAME:
        {
            bt_bdname_t *bd_name = (bt_bdname_t*)prop->val;
            strncpy((char *)bd_name->name,btif_get_default_local_name(),
            strncpy((char *)bd_name->name, (char *)btif_get_default_local_name(),
                   sizeof(bd_name->name) - 1);
            bd_name->name[sizeof(bd_name->name) - 1] = 0;
            prop->len = strlen((char *)bd_name->name);
+14 −10
Original line number Diff line number Diff line
@@ -129,7 +129,7 @@ void btif_pan_init()
    {
        BTIF_TRACE_DEBUG("Enabling PAN....");
        memset(&btpan_cb, 0, sizeof(btpan_cb));
        btpan_cb.tap_fd = -1;
        btpan_cb.tap_fd = INVALID_FD;
        btpan_cb.flow = 1;
        int i;
        for(i = 0; i < MAX_PAN_CONNS; i++)
@@ -146,10 +146,10 @@ static void pan_disable()
    {
        btpan_cb.enabled = 0;
        BTA_PanDisable();
        if(btpan_cb.tap_fd != -1)
        if (btpan_cb.tap_fd != INVALID_FD)
        {
            btpan_tap_close(btpan_cb.tap_fd);
            btpan_cb.tap_fd = -1;
            btpan_cb.tap_fd = INVALID_FD;
        }
    }
}
@@ -312,6 +312,8 @@ static int tap_if_up(const char *devname, const bt_bdaddr_t *addr)
    int sk, err;

    sk = socket(AF_INET, SOCK_DGRAM, 0);
    if(sk < 0)
        return -1 ;

    //set mac addr
    memset(&ifr, 0, sizeof(ifr));
@@ -371,6 +373,8 @@ static int tap_if_down(const char *devname)
    int sk;

    sk = socket(AF_INET, SOCK_DGRAM, 0);
    if(sk < 0)
        return -1 ;

    memset(&ifr, 0, sizeof(ifr));
    strncpy(ifr.ifr_name, devname, IF_NAMESIZE - 1);
@@ -429,7 +433,7 @@ int btpan_tap_open()
    }
    BTIF_TRACE_ERROR("can not bring up tap interface:%s", TAP_IF_NAME);
    close(fd);
    return -1;
    return INVALID_FD;
}

int btpan_tap_send(int tap_fd, const BD_ADDR src, const BD_ADDR dst, UINT16 proto, const char* buf,
@@ -437,7 +441,7 @@ int btpan_tap_send(int tap_fd, const BD_ADDR src, const BD_ADDR dst, UINT16 prot
{
    UNUSED(ext);
    UNUSED(forward);
    if(tap_fd != -1)
    if(tap_fd != INVALID_FD)
    {
        tETH_HDR eth_hdr;
        memcpy(&eth_hdr.h_dest, dst, ETH_ADDR_LEN);
@@ -463,7 +467,7 @@ int btpan_tap_send(int tap_fd, const BD_ADDR src, const BD_ADDR dst, UINT16 prot

int btpan_tap_close(int fd)
{
    tap_if_down(TAP_IF_NAME);
    if(tap_if_down(TAP_IF_NAME) == 0)
        close(fd);
    if(pan_pth >= 0)
        btsock_thread_wakeup(pan_pth);
@@ -661,7 +665,7 @@ static void btu_exec_tap_fd_read(void *p_param) {
    struct pollfd ufd;
    int fd = (int)p_param;

    if (fd == -1 || fd != btpan_cb.tap_fd)
    if (fd == INVALID_FD || fd != btpan_cb.tap_fd)
        return;

    // Don't occupy BTU context too long, avoid GKI buffer overruns and
@@ -753,7 +757,7 @@ static void btpan_tap_fd_signaled(int fd, int type, int flags, uint32_t user_id)
    }

    if(flags & SOCK_THREAD_FD_EXCEPTION) {
        btpan_cb.tap_fd = -1;
        btpan_cb.tap_fd = INVALID_FD;
        btpan_tap_close(fd);
        btif_pan_close_all_conns();
    } else if(flags & SOCK_THREAD_FD_RD)
Loading