On Thu, Nov 5, 2026 at 2:54 PM Philippe Mathieu-Daudé <
[email protected]> wrote:

> Formatting is not necessary, replace the deprecated
> sprintf() by StrCpyNA() and StrCatBuffA() calls.
>
> Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
> ---
>  qga/vss-win32/install.cpp | 17 ++++++++++++-----
>  1 file changed, 12 insertions(+), 5 deletions(-)
>
> diff --git a/qga/vss-win32/install.cpp b/qga/vss-win32/install.cpp
> index df00588c923a..1a3d5cbf75d5 100644
> --- a/qga/vss-win32/install.cpp
> +++ b/qga/vss-win32/install.cpp
> @@ -562,7 +562,8 @@ STDAPI DllRegisterServer(void)
>
>      /* Add this module to registry */
>
> -    sprintf(key, "CLSID\\%s", g_szClsid);
> +    StrCpyNA(key, "CLSID\\", sizeof(key));
> +    StrCatBuffA(key, g_szClsid, sizeof(key));
>

MSFT does not recommend to use StrCatBuffA due to security warning.
What about using StringCchCatA instead of snprintf, even in this case?


>      if (!CreateRegistryKey(key, NULL, g_szClsid)) {
>          goto out;
>      }
> @@ -572,7 +573,9 @@ STDAPI DllRegisterServer(void)
>          goto out;
>      }
>
> -    sprintf(key, "CLSID\\%s\\InprocServer32", g_szClsid);
> +    StrCpyNA(key, "CLSID\\", sizeof(key));
> +    StrCatBuffA(key, g_szClsid, sizeof(key));
> +    StrCatBuffA(key, "\\InprocServer32", sizeof(key));
>      if (!CreateRegistryKey(key, NULL, dllPath)) {
>          goto out;
>      }
> @@ -581,7 +584,9 @@ STDAPI DllRegisterServer(void)
>          goto out;
>      }
>
> -    sprintf(key, "CLSID\\%s\\ProgID", g_szClsid);
> +    StrCpyNA(key, "CLSID\\", sizeof(key));
> +    StrCatBuffA(key, g_szClsid, sizeof(key));
> +    StrCatBuffA(key, "\\ProgID", sizeof(key));
>      if (!CreateRegistryKey(key, NULL, g_szProgid)) {
>          goto out;
>      }
> @@ -590,7 +595,8 @@ STDAPI DllRegisterServer(void)
>          goto out;
>      }
>
> -    sprintf(key, "%s\\CLSID", g_szProgid);
> +    StrCpyNA(key, g_szProgid, sizeof(key));
> +    StrCatBuffA(key, "\\CLSID", sizeof(key));
>      if (!CreateRegistryKey(key, NULL, g_szClsid)) {
>          goto out;
>      }
> @@ -651,7 +657,8 @@ STDAPI DllUnregisterServer(void)
>          errmsg(hr, "CoCreateInstance(VSSCoordinator) failed");
>      }
>
> -    sprintf(key, "CLSID\\%s", g_szClsid);
> +    StrCpyNA(key, "CLSID\\", sizeof(key));
> +    StrCatBuffA(key, g_szClsid, sizeof(key));
>      SHDeleteKey(HKEY_CLASSES_ROOT, key);
>      SHDeleteKey(HKEY_CLASSES_ROOT, g_szProgid);
>
> --
> 2.55.0
>
>

Reply via email to