From: Candy Febriyanto Date: Mon, 1 Mar 2021 15:01:50 +0000 (+0700) Subject: staging: rtl8723bs: hal: Replace sprintf with scnprintf X-Git-Tag: v5.13-rc1~173^2~624 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=2a02059e4f9ed59817d8c238f93bb8e5c58562ad;p=tomoyo%2Ftomoyo-test1.git staging: rtl8723bs: hal: Replace sprintf with scnprintf The use of sprintf with format string here means that there is a risk that the writes will go out of bounds, replace it with scnprintf. Also avoid unnecessarily passing "%s" on some of the function calls. Reviewed-by: Hans de Goede Signed-off-by: Candy Febriyanto Link: https://lore.kernel.org/r/ed564fb9e325f757b2b937df37689d40b96d8831.1614610197.git.cfebriyanto@gmail.com Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/rtl8723bs/hal/hal_com.c b/drivers/staging/rtl8723bs/hal/hal_com.c index 16b259acbe1a..173ccaba2537 100644 --- a/drivers/staging/rtl8723bs/hal/hal_com.c +++ b/drivers/staging/rtl8723bs/hal/hal_com.c @@ -40,47 +40,50 @@ void rtw_hal_data_deinit(struct adapter *padapter) void dump_chip_info(HAL_VERSION ChipVersion) { - int cnt = 0; - u8 buf[128]; + char buf[128]; + size_t cnt = 0; + + cnt += scnprintf(buf + cnt, sizeof(buf) - cnt, "Chip Version Info: CHIP_8723B_%s_", + IS_NORMAL_CHIP(ChipVersion) ? "Normal_Chip" : "Test_Chip"); - cnt += sprintf((buf+cnt), "Chip Version Info: CHIP_8723B_"); - cnt += sprintf((buf+cnt), "%s_", IS_NORMAL_CHIP(ChipVersion) ? "Normal_Chip" : "Test_Chip"); if (IS_CHIP_VENDOR_TSMC(ChipVersion)) - cnt += sprintf((buf+cnt), "%s_", "TSMC"); + cnt += scnprintf(buf + cnt, sizeof(buf) - cnt, "TSMC_"); else if (IS_CHIP_VENDOR_UMC(ChipVersion)) - cnt += sprintf((buf+cnt), "%s_", "UMC"); + cnt += scnprintf(buf + cnt, sizeof(buf) - cnt, "UMC_"); else if (IS_CHIP_VENDOR_SMIC(ChipVersion)) - cnt += sprintf((buf+cnt), "%s_", "SMIC"); + cnt += scnprintf(buf + cnt, sizeof(buf) - cnt, "SMIC_"); if (IS_A_CUT(ChipVersion)) - cnt += sprintf((buf+cnt), "A_CUT_"); + cnt += scnprintf(buf + cnt, sizeof(buf) - cnt, "A_CUT_"); else if (IS_B_CUT(ChipVersion)) - cnt += sprintf((buf+cnt), "B_CUT_"); + cnt += scnprintf(buf + cnt, sizeof(buf) - cnt, "B_CUT_"); else if (IS_C_CUT(ChipVersion)) - cnt += sprintf((buf+cnt), "C_CUT_"); + cnt += scnprintf(buf + cnt, sizeof(buf) - cnt, "C_CUT_"); else if (IS_D_CUT(ChipVersion)) - cnt += sprintf((buf+cnt), "D_CUT_"); + cnt += scnprintf(buf + cnt, sizeof(buf) - cnt, "D_CUT_"); else if (IS_E_CUT(ChipVersion)) - cnt += sprintf((buf+cnt), "E_CUT_"); + cnt += scnprintf(buf + cnt, sizeof(buf) - cnt, "E_CUT_"); else if (IS_I_CUT(ChipVersion)) - cnt += sprintf((buf+cnt), "I_CUT_"); + cnt += scnprintf(buf + cnt, sizeof(buf) - cnt, "I_CUT_"); else if (IS_J_CUT(ChipVersion)) - cnt += sprintf((buf+cnt), "J_CUT_"); + cnt += scnprintf(buf + cnt, sizeof(buf) - cnt, "J_CUT_"); else if (IS_K_CUT(ChipVersion)) - cnt += sprintf((buf+cnt), "K_CUT_"); + cnt += scnprintf(buf + cnt, sizeof(buf) - cnt, "K_CUT_"); else - cnt += sprintf((buf+cnt), "UNKNOWN_CUT(%d)_", ChipVersion.CUTVersion); + cnt += scnprintf(buf + cnt, sizeof(buf) - cnt, + "UNKNOWN_CUT(%d)_", ChipVersion.CUTVersion); if (IS_1T1R(ChipVersion)) - cnt += sprintf((buf+cnt), "1T1R_"); + cnt += scnprintf(buf + cnt, sizeof(buf) - cnt, "1T1R_"); else if (IS_1T2R(ChipVersion)) - cnt += sprintf((buf+cnt), "1T2R_"); + cnt += scnprintf(buf + cnt, sizeof(buf) - cnt, "1T2R_"); else if (IS_2T2R(ChipVersion)) - cnt += sprintf((buf+cnt), "2T2R_"); + cnt += scnprintf(buf + cnt, sizeof(buf) - cnt, "2T2R_"); else - cnt += sprintf((buf+cnt), "UNKNOWN_RFTYPE(%d)_", ChipVersion.RFType); + cnt += scnprintf(buf + cnt, sizeof(buf) - cnt, + "UNKNOWN_RFTYPE(%d)_", ChipVersion.RFType); - cnt += sprintf((buf+cnt), "RomVer(%d)\n", ChipVersion.ROMVer); + cnt += scnprintf(buf + cnt, sizeof(buf) - cnt, "RomVer(%d)\n", ChipVersion.ROMVer); DBG_871X("%s", buf); }