wincng.c: fix possible invalid memory write access

Fixes VS2012 code analysis warning C6386:
buffer overrun: accessing 'pbOutput', the writable size is
'cbOutput' bytes, but '3' bytes may be written: libssh2 wincng.c 610
This commit is contained in:
Marc Hoersken
2014-12-15 00:38:58 +01:00
parent f89bed9571
commit f31c9fb221

View File

@@ -597,16 +597,17 @@ _libssh2_wincng_bn_ltob(unsigned char *pbInput,
cbOutput = cbInput; cbOutput = cbInput;
if (pbInput[length] & (1 << 7)) { if (pbInput[length] & (1 << 7)) {
offset++; offset++;
cbOutput++; cbOutput += offset;
} }
pbOutput = malloc(cbOutput); pbOutput = (unsigned char *)malloc(cbOutput);
if (!pbOutput) { if (!pbOutput) {
return -1; return -1;
} }
pbOutput[0] = 0; pbOutput[0] = 0;
for (index = 0; index < cbInput; index++) { for (index = 0; ((index + offset) < cbOutput)
&& (index < cbInput); index++) {
pbOutput[index + offset] = pbInput[length - index]; pbOutput[index + offset] = pbInput[length - index];
} }