Ticket #11428: blue.patch

File blue.patch, 1.8 KB (added by Karvjorm, 9 years ago)
  • headers/os/bluetooth/LinkKeyUtils.h

    diff --git a/headers/os/bluetooth/LinkKeyUtils.h b/headers/os/bluetooth/LinkKeyUtils.h
    index 3abbb31..5b7dbf2 100644
    a b public:  
    2626   
    2727    static char* ToString(const linkkey_t lk)
    2828    {
    29         // TODO: not safe
    30         static char str[50];
     29        int LEN = 51;
     30        static char str[LEN];
     31        int ret = 0;
    3132
    32         sprintf(str, "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:"
     33        ret = snprintf(str, (size_t)LEN,
     34                "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:"
    3335                "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
    3436                lk.l[0], lk.l[1], lk.l[2], lk.l[3], lk.l[4], lk.l[5],
    3537                lk.l[6], lk.l[7], lk.l[8], lk.l[9], lk.l[10], lk.l[11],
    3638                lk.l[12], lk.l[13], lk.l[14], lk.l[15]);
     39               
     40        if (ret <= 0) {
     41            snprintf(str, (size_t)LEN,
     42                "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:"
     43                "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
     44                0, 0, 0, 0, 0, 0,
     45                0, 0, 0, 0, 0, 0,
     46                0, 0, 0, 0);
     47        }
    3748
    3849        return str;
    3950    }
  • headers/os/bluetooth/bdaddrUtils.h

    diff --git a/headers/os/bluetooth/bdaddrUtils.h b/headers/os/bluetooth/bdaddrUtils.h
    index 9b86c32..2038a6a 100644
    a b public:  
    4747
    4848    static char* ToString(const bdaddr_t bdaddr)
    4949    {
    50         // TODO: not safe
    51         static char str[18];
    52 
    53         sprintf(str,"%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",bdaddr.b[5],
    54                 bdaddr.b[4], bdaddr.b[3], bdaddr.b[2], bdaddr.b[1],
    55                 bdaddr.b[0]);
     50        int LEN = 19;
     51        static char str[LEN];
     52        int ret = 0;
     53        ret = snprintf(str, (size_t)LEN,
     54                    "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
     55                    bdaddr.b[5], bdaddr.b[4], bdaddr.b[3],
     56                    bdaddr.b[2], bdaddr.b[1], bdaddr.b[0]);
     57        if (ret <= 0) {
     58            snprintf(str, (size_t)LEN,
     59                    "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
     60                    0, 0, 0, 0, 0, 0);
     61        }
    5662        return str;
    5763    }