From f8f6b6580778474992d3997bc301146bf54d6cbd Mon Sep 17 00:00:00 2001 From: XZ-X Date: Wed, 24 Jul 2024 15:53:29 -0400 Subject: [PATCH] null pointer checks for strdup and kstrdup --- patches/driver/brcmfmac_5.15.y-nexmon/firmware.c | 10 ++++++++-- patches/driver/brcmfmac_6.1.y-nexmon/firmware.c | 5 +++++ patches/driver/brcmfmac_6.2.y-nexmon/firmware.c | 5 +++++ patches/driver/brcmfmac_6.6.y-nexmon/firmware.c | 5 +++++ utilities/aircrack-ng/src/aircrack-ng.c | 5 +++++ 5 files changed, 28 insertions(+), 2 deletions(-) diff --git a/patches/driver/brcmfmac_5.15.y-nexmon/firmware.c b/patches/driver/brcmfmac_5.15.y-nexmon/firmware.c index c5497208f..ba000d1e0 100644 --- a/patches/driver/brcmfmac_5.15.y-nexmon/firmware.c +++ b/patches/driver/brcmfmac_5.15.y-nexmon/firmware.c @@ -617,6 +617,7 @@ static char *brcm_alt_fw_path(const char *path, const char *board_type) { char alt_path[BRCMF_FW_NAME_LEN]; char suffix[5]; + char *ret = NULL; strscpy(alt_path, path, BRCMF_FW_NAME_LEN); /* At least one character + suffix */ @@ -629,8 +630,13 @@ static char *brcm_alt_fw_path(const char *path, const char *board_type) strlcat(alt_path, ".", BRCMF_FW_NAME_LEN); strlcat(alt_path, board_type, BRCMF_FW_NAME_LEN); strlcat(alt_path, suffix, BRCMF_FW_NAME_LEN); - - return kstrdup(alt_path, GFP_KERNEL); + ret = kstrdup(alt_path, GFP_KERNEL); + if (!ret) { + brcmf_err("failed to allocate memory for alt_path\n"); + return NULL; + } + + return ret; } static int brcmf_fw_request_firmware(const struct firmware **fw, diff --git a/patches/driver/brcmfmac_6.1.y-nexmon/firmware.c b/patches/driver/brcmfmac_6.1.y-nexmon/firmware.c index 22a0562b3..62e82cdcd 100644 --- a/patches/driver/brcmfmac_6.1.y-nexmon/firmware.c +++ b/patches/driver/brcmfmac_6.1.y-nexmon/firmware.c @@ -608,6 +608,7 @@ static char *brcm_alt_fw_path(const char *path, const char *board_type) { char alt_path[BRCMF_FW_NAME_LEN]; char suffix[5]; + char *ret = NULL; strscpy(alt_path, path, BRCMF_FW_NAME_LEN); /* At least one character + suffix */ @@ -620,6 +621,10 @@ static char *brcm_alt_fw_path(const char *path, const char *board_type) strlcat(alt_path, ".", BRCMF_FW_NAME_LEN); strlcat(alt_path, board_type, BRCMF_FW_NAME_LEN); strlcat(alt_path, suffix, BRCMF_FW_NAME_LEN); + if (!ret) { + brcmf_err("failed to allocate memory for alt_path\n"); + return NULL; + } return kstrdup(alt_path, GFP_KERNEL); } diff --git a/patches/driver/brcmfmac_6.2.y-nexmon/firmware.c b/patches/driver/brcmfmac_6.2.y-nexmon/firmware.c index 22a0562b3..62e82cdcd 100644 --- a/patches/driver/brcmfmac_6.2.y-nexmon/firmware.c +++ b/patches/driver/brcmfmac_6.2.y-nexmon/firmware.c @@ -608,6 +608,7 @@ static char *brcm_alt_fw_path(const char *path, const char *board_type) { char alt_path[BRCMF_FW_NAME_LEN]; char suffix[5]; + char *ret = NULL; strscpy(alt_path, path, BRCMF_FW_NAME_LEN); /* At least one character + suffix */ @@ -620,6 +621,10 @@ static char *brcm_alt_fw_path(const char *path, const char *board_type) strlcat(alt_path, ".", BRCMF_FW_NAME_LEN); strlcat(alt_path, board_type, BRCMF_FW_NAME_LEN); strlcat(alt_path, suffix, BRCMF_FW_NAME_LEN); + if (!ret) { + brcmf_err("failed to allocate memory for alt_path\n"); + return NULL; + } return kstrdup(alt_path, GFP_KERNEL); } diff --git a/patches/driver/brcmfmac_6.6.y-nexmon/firmware.c b/patches/driver/brcmfmac_6.6.y-nexmon/firmware.c index 22a0562b3..8b6c50d44 100644 --- a/patches/driver/brcmfmac_6.6.y-nexmon/firmware.c +++ b/patches/driver/brcmfmac_6.6.y-nexmon/firmware.c @@ -608,6 +608,7 @@ static char *brcm_alt_fw_path(const char *path, const char *board_type) { char alt_path[BRCMF_FW_NAME_LEN]; char suffix[5]; + char *ret; strscpy(alt_path, path, BRCMF_FW_NAME_LEN); /* At least one character + suffix */ @@ -620,6 +621,10 @@ static char *brcm_alt_fw_path(const char *path, const char *board_type) strlcat(alt_path, ".", BRCMF_FW_NAME_LEN); strlcat(alt_path, board_type, BRCMF_FW_NAME_LEN); strlcat(alt_path, suffix, BRCMF_FW_NAME_LEN); + if (!ret) { + brcmf_err("failed to allocate memory for alt_path\n"); + return NULL; + } return kstrdup(alt_path, GFP_KERNEL); } diff --git a/utilities/aircrack-ng/src/aircrack-ng.c b/utilities/aircrack-ng/src/aircrack-ng.c index 37b2f0882..f1f7d7f22 100644 --- a/utilities/aircrack-ng/src/aircrack-ng.c +++ b/utilities/aircrack-ng/src/aircrack-ng.c @@ -710,6 +710,11 @@ int mergebssids(char * bssidlist, unsigned char * bssid) mac[17] = 0; tmp2 = list = strdup(bssidlist); + if (list == NULL) + { + perror( "strdup failed" ); + return -1; + } // skip first element (because it doesn't have to be converted // It already has the good value