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

Commit 11d4ab8f authored by Gabriel Biren's avatar Gabriel Biren
Browse files

Replace instances of strncpy and sprintf in the wifi

vendor HAL with strlcpy and snprintf.

Bug: 218897284
Test: m
Change-Id: I0a62d1c5043cabcf6a513b8b082ad1d7a1ea451c
parent 89345a4d
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -1881,7 +1881,7 @@ bool convertHidlNanDataPathInitiatorRequestToLegacy(
                      "ifaceName too long";
        return false;
    }
    strncpy(legacy_request->ndp_iface, hidl_request.ifaceName.c_str(), IFNAMSIZ + 1);
    strlcpy(legacy_request->ndp_iface, hidl_request.ifaceName.c_str(), IFNAMSIZ + 1);
    legacy_request->ndp_cfg.security_cfg =
            (hidl_request.securityConfig.securityType != NanDataPathSecurityType::OPEN)
                    ? legacy_hal::NAN_DP_CONFIG_SECURITY
@@ -1958,7 +1958,7 @@ bool convertHidlNanDataPathInitiatorRequest_1_6ToLegacy(
                      "ifaceName too long";
        return false;
    }
    strncpy(legacy_request->ndp_iface, hidl_request.ifaceName.c_str(), IFNAMSIZ + 1);
    strlcpy(legacy_request->ndp_iface, hidl_request.ifaceName.c_str(), IFNAMSIZ + 1);
    legacy_request->ndp_cfg.security_cfg =
            (hidl_request.securityConfig.securityType != NanDataPathSecurityType::OPEN)
                    ? legacy_hal::NAN_DP_CONFIG_SECURITY
@@ -2039,7 +2039,7 @@ bool convertHidlNanDataPathIndicationResponseToLegacy(
                      "ifaceName too long";
        return false;
    }
    strncpy(legacy_request->ndp_iface, hidl_request.ifaceName.c_str(), IFNAMSIZ + 1);
    strlcpy(legacy_request->ndp_iface, hidl_request.ifaceName.c_str(), IFNAMSIZ + 1);
    legacy_request->ndp_cfg.security_cfg =
            (hidl_request.securityConfig.securityType != NanDataPathSecurityType::OPEN)
                    ? legacy_hal::NAN_DP_CONFIG_SECURITY
@@ -2114,7 +2114,7 @@ bool convertHidlNanDataPathIndicationResponse_1_6ToLegacy(
                      "ifaceName too long";
        return false;
    }
    strncpy(legacy_request->ndp_iface, hidl_request.ifaceName.c_str(), IFNAMSIZ + 1);
    strlcpy(legacy_request->ndp_iface, hidl_request.ifaceName.c_str(), IFNAMSIZ + 1);
    legacy_request->ndp_cfg.security_cfg =
            (hidl_request.securityConfig.securityType != NanDataPathSecurityType::OPEN)
                    ? legacy_hal::NAN_DP_CONFIG_SECURITY
+14 −12
Original line number Diff line number Diff line
@@ -131,7 +131,7 @@ std::string getPredefinedP2pIfaceName() {
    if (strncmp(buffer.data(), P2P_MGMT_DEVICE_PREFIX, strlen(P2P_MGMT_DEVICE_PREFIX)) == 0) {
        /* Get the p2p parent interface name from p2p device interface name set
         * in property */
        strncpy(p2pParentIfname, buffer.data() + strlen(P2P_MGMT_DEVICE_PREFIX),
        strlcpy(p2pParentIfname, buffer.data() + strlen(P2P_MGMT_DEVICE_PREFIX),
                strlen(buffer.data()) - strlen(P2P_MGMT_DEVICE_PREFIX));
        if (property_get(kActiveWlanIfaceNameProperty, primaryIfaceName.data(), nullptr) == 0) {
            return buffer.data();
@@ -217,14 +217,15 @@ bool removeOldFilesInternal() {

// Helper function for |cpioArchiveFilesInDir|
bool cpioWriteHeader(int out_fd, struct stat& st, const char* file_name, size_t file_name_len) {
    std::array<char, 32 * 1024> read_buf;
    ssize_t llen =
            sprintf(read_buf.data(), "%s%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X",
    const int buf_size = 32 * 1024;
    std::array<char, buf_size> read_buf;
    ssize_t llen = snprintf(
            read_buf.data(), buf_size, "%s%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X",
            kCpioMagic, static_cast<int>(st.st_ino), st.st_mode, st.st_uid, st.st_gid,
            static_cast<int>(st.st_nlink), static_cast<int>(st.st_mtime),
                    static_cast<int>(st.st_size), major(st.st_dev), minor(st.st_dev),
                    major(st.st_rdev), minor(st.st_rdev), static_cast<uint32_t>(file_name_len), 0);
    if (write(out_fd, read_buf.data(), llen) == -1) {
            static_cast<int>(st.st_size), major(st.st_dev), minor(st.st_dev), major(st.st_rdev),
            minor(st.st_rdev), static_cast<uint32_t>(file_name_len), 0);
    if (write(out_fd, read_buf.data(), llen < buf_size ? llen : buf_size - 1) == -1) {
        PLOG(ERROR) << "Error writing cpio header to file " << file_name;
        return false;
    }
@@ -282,10 +283,11 @@ size_t cpioWriteFileContent(int fd_read, int out_fd, struct stat& st) {

// Helper function for |cpioArchiveFilesInDir|
bool cpioWriteFileTrailer(int out_fd) {
    std::array<char, 4096> read_buf;
    const int buf_size = 4096;
    std::array<char, buf_size> read_buf;
    read_buf.fill(0);
    if (write(out_fd, read_buf.data(),
              sprintf(read_buf.data(), "070701%040X%056X%08XTRAILER!!!", 1, 0x0b, 0) + 4) == -1) {
    ssize_t llen = snprintf(read_buf.data(), 4096, "070701%040X%056X%08XTRAILER!!!", 1, 0x0b, 0);
    if (write(out_fd, read_buf.data(), (llen < buf_size ? llen : buf_size - 1) + 4) == -1) {
        PLOG(ERROR) << "Error writing trailing bytes";
        return false;
    }