summaryrefslogtreecommitdiff
path: root/src/nativeresources
diff options
context:
space:
mode:
authorYi Zhang (CLR) <yizhang82@users.noreply.github.com>2017-06-02 09:10:34 -0700
committerJan Vorlicek <janvorli@microsoft.com>2017-06-02 18:10:34 +0200
commit3a6895ebcc29e0ad84bef61a216433e99fda5f6c (patch)
tree3f208a02733279189334b651e69f930c4dc92f40 /src/nativeresources
parentef4b192c83f7edd90c75d65ba5440327b3f9d276 (diff)
downloadcoreclr-3a6895ebcc29e0ad84bef61a216433e99fda5f6c.tar.gz
coreclr-3a6895ebcc29e0ad84bef61a216433e99fda5f6c.tar.bz2
coreclr-3a6895ebcc29e0ad84bef61a216433e99fda5f6c.zip
Fix a bug in LoadNativeStringResource to honor the contract properly when the buffer is not big enough (#12051)
* Return last error properly * adjust pcwchUsed if ERROR_INSUFFICIENT_BUFFER * return hr * ERROR_INSUFFICIENT_BUFFER is a win32 error....
Diffstat (limited to 'src/nativeresources')
-rw-r--r--src/nativeresources/resourcestring.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/nativeresources/resourcestring.cpp b/src/nativeresources/resourcestring.cpp
index 236a2a3ca7..1c3f50a1c4 100644
--- a/src/nativeresources/resourcestring.cpp
+++ b/src/nativeresources/resourcestring.cpp
@@ -38,6 +38,16 @@ int LoadNativeStringResource(const NativeStringResourceTable &nativeStringResour
if (resourceEntry != NULL)
{
len = PAL_GetResourceString(NULL, resourceEntry->resourceString, szBuffer, iMax);
+ if (len == 0)
+ {
+ int hr = HRESULT_FROM_GetLastError();
+
+ // Tell the caller if the buffer isn't big enough
+ if (hr == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER) && pcwchUsed)
+ *pcwchUsed = iMax;
+
+ return hr;
+ }
}
else
{
@@ -47,6 +57,8 @@ int LoadNativeStringResource(const NativeStringResourceTable &nativeStringResour
{
// The only possible failure is that that string didn't fit the buffer. So the buffer contains
// partial string terminated by '\0'
+ // We could return ERROR_INSUFFICIENT_BUFFER, but we'll error on the side of caution here and
+ // actually show something (given that this is likely a scenario involving a bug/deployment issue)
len = iMax - 1;
}
}