From 825f4ed2ef7cbf935eafb25d32d01706a98aa6ef Mon Sep 17 00:00:00 2001 From: Bill Zissimopoulos Date: Tue, 15 Dec 2015 16:06:02 -0800 Subject: [PATCH] dll: remove references to StringCbPrintf*() --- src/dll/debug.c | 6 ++++-- src/dll/fsctl.c | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/dll/debug.c b/src/dll/debug.c index 78a10d53..7b389e9c 100644 --- a/src/dll/debug.c +++ b/src/dll/debug.c @@ -9,10 +9,12 @@ FSP_API VOID FspDebugLog(const char *format, ...) { - char buf[512]; + char buf[1024]; + /* DbgPrint has a 512 byte limit, but wvsprintf is only safe with a 1024 byte buffer */ va_list ap; va_start(ap, format); - StringCbVPrintfA(buf, sizeof buf, format, ap); + wvsprintfA(buf, format, ap); va_end(ap); + buf[sizeof buf - 1] = '\0'; OutputDebugStringA(buf); } diff --git a/src/dll/fsctl.c b/src/dll/fsctl.c index fadc2608..baf12790 100644 --- a/src/dll/fsctl.c +++ b/src/dll/fsctl.c @@ -13,8 +13,18 @@ static inline VOID GlobalDevicePath(PWCHAR DevicePathBuf, SIZE_T DevicePathSize, PWSTR DevicePath) { - StringCbPrintfW(DevicePathBuf, DevicePathSize, - L'\\' == DevicePath[0] ? GLOBALROOT "%s" : GLOBALROOT "\\Device\\%s", DevicePath); + PWSTR DeviceRoot = L'\\' == DevicePath[0] ? GLOBALROOT : GLOBALROOT "\\Device\\"; + SIZE_T RootSize = lstrlenW(DeviceRoot) * sizeof(WCHAR); + SIZE_T PathSize = lstrlenW(DevicePath) * sizeof(WCHAR) + sizeof(WCHAR); + + if (RootSize + PathSize <= DevicePathSize) + { + memcpy(DevicePathBuf, DeviceRoot, RootSize); + memcpy(DevicePathBuf + RootSize, DevicePath, PathSize); + } + else + /* we should be doing assert(sizeof(WCHAR) <= DevicePathSize), but we don't have assert! */ + DevicePathBuf[0] = L'\0'; } static NTSTATUS CreateSelfRelativeSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor,