*/
escapedLen = HgfsEscape_GetSize(begin, len);
- if (0 == escapedLen) {
+ if (escapedLen < 0) {
+ Log("%s: error calculating buffer size\n", __FUNCTION__);
+ return FALSE;
+ } else if (0 == escapedLen) {
newDataLen += rootLen + len + 1;
newData = (char *)Util_SafeRealloc(newData, newDataLen);
}
myNext = walk + 1;
+ /* Skip consecutive path delimiters. */
+ while ((*myNext == '\0') && (myNext != end)) {
+ myNext++;
+ }
if (myNext == end) {
/* Last character in the buffer is not allowed to be NUL */
+ Log("%s: error: last char can't be NUL\n", __FUNCTION__);
return -1;
}
char pathSep) // IN: Path separator character
{
int result;
- size_t inputSize;
+ int inputSize;
inputSize = HgfsEscape_GetSize(*bufIn, *inSize);
- if (inputSize != 0) {
+ if (inputSize < 0) {
+ result = -1;
+ } else if (inputSize != 0) {
char *savedBufOut = *bufOut;
char const *savedOutConst = savedBufOut;
size_t savedOutSize = *outSize;
nameIn++;
}
- /* Copy the string to the output buf, converting all path separators into '\0'. */
- for (; *nameIn != '\0' && bufOut < endOut; nameIn++) {
- *bufOut = (*nameIn == pathSep) ? '\0' : *nameIn;
+ /*
+ * Copy the string to the output buf, converting all path separators into '\0'.
+ * Collapse multiple consecutive path separators into a single one since
+ * CPName_GetComponent can't handle consecutive path separators.
+ */
+ while (*nameIn != '\0' && bufOut < endOut) {
+ if (*nameIn == pathSep) {
+ *bufOut = '\0';
+ do {
+ nameIn++;
+ } while (*nameIn == pathSep);
+ } else {
+ *bufOut = *nameIn;
+ nameIn++;
+ }
bufOut++;
}
}
while (currentComponent - bufIn < sizeIn) {
int escapedLength;
- uint32 componentSize = CPName_GetComponent(currentComponent, end, &next);
+ int componentSize = CPName_GetComponent(currentComponent, end, &next);
+ if (componentSize < 0) {
+ return componentSize;
+ }
escapedLength = HgfsEscapeDoComponent(currentComponent, componentSize,
sizeLeft, outPointer);
currentComponent++;
}
while (currentComponent - bufIn < sizeIn) {
- uint32 componentSize = CPName_GetComponent(currentComponent, end, &next);
+ int componentSize = CPName_GetComponent(currentComponent, end, &next);
+ if (componentSize < 0) {
+ Log("%s: failed to calculate escapde name size - name is invalid\n", __FUNCTION__);
+ return -1;
+ }
result += HgfsEscapeGetComponentSize(currentComponent, componentSize);
currentComponent = next;
}