YottaDB / YDB

Mirrored from https://gitlab.com/YottaDB/DB/YDB
Other
76 stars 37 forks source link

[#264] Fix buffer overflow in MUPIP BACKUP that can cause SIGABRT/SIG-6 errors #268

Closed nars1 closed 6 years ago

nars1 commented 6 years ago

The check for whether the temporary file name is longer than the allocated buffer can hold was incorrect. It was assuming 4 bytes (SIZEOF(uint4)) for the string that followed the hexadecimal process-id but the actual name had _XXXXXX following it which accounts for 7 bytes. For example, the actual temporary file name was DEFAULT_17fa_XXXXXX (where XXXXXX was replaced with a temporary string by "mkstemp") but the check was accounting only for DEFAULT_17fa_XXX. So there was a potential for a 3-byte overflow to go unnoticed. This logic is now reworked to use SNPRINTF to let us accurately know if the allocated buffer is not enough and if so issue a FILENAMETOOLONG error.

In addition, the FILENAMETOOLONG error is now prefixed with a FILEPARSE error message which prints the entire path name that exceeded the 255 byte limit. Previously this only printed the absolute directory path without including the temporary file name. This could be potentially confusing to the user since they would see the directory path printed in the FILEPARSE error message is less than 255 characters but still an error is being issued saying it is longer than 255 characters.

nars1 commented 6 years ago

For the record. Even though this pull request identifies the issue # as #264, it actually fixes #267.