Fix buffer overflow in epicsStrnRawFromEscaped

lp:1388313
This commit is contained in:
Andrew Johnson
2014-11-05 10:06:02 -06:00
parent 9f163ef8d9
commit 53d9a07f64
3 changed files with 50 additions and 2 deletions
+6 -1
View File
@@ -43,6 +43,9 @@ int epicsStrnRawFromEscaped(char *to, size_t outsize, const char *from,
char c;
int nto = 0, nfrom = 0;
if (outsize == 0)
return 0;
while ((c = *pfrom++) && nto < outsize && nfrom < inlen) {
nfrom++;
if (c == '\\') {
@@ -100,7 +103,9 @@ int epicsStrnRawFromEscaped(char *to, size_t outsize, const char *from,
*pto++ = c; nto++;
}
}
*pto = '\0'; /* NOTE that nto does not have to be incremented */
if (nto == outsize)
pto--;
*pto = '\0';
return nto;
}