SubPathAdder: Check for overflows, omit initial /
This commit is contained in:
@@ -196,17 +196,28 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
struct PackageWriterImpl::SubPathAdder {
|
struct PackageWriterImpl::SubPathAdder {
|
||||||
SubPathAdder(char* pathBuffer, const char* subPath)
|
SubPathAdder(BErrorOutput* errorOutput, char* pathBuffer,
|
||||||
: fOriginalPathEnd(pathBuffer + strlen(pathBuffer))
|
const char* subPath)
|
||||||
|
:
|
||||||
|
fOriginalPathEnd(pathBuffer + strlen(pathBuffer))
|
||||||
{
|
{
|
||||||
strcat(pathBuffer, "/");
|
if (fOriginalPathEnd != pathBuffer)
|
||||||
strcat(pathBuffer, subPath);
|
strlcat(pathBuffer, "/", B_PATH_NAME_LENGTH);
|
||||||
|
|
||||||
|
if (strlcat(pathBuffer, subPath, B_PATH_NAME_LENGTH)
|
||||||
|
>= B_PATH_NAME_LENGTH) {
|
||||||
|
*fOriginalPathEnd = '\0';
|
||||||
|
errorOutput->PrintError("Path too long: \"%s/%s\"\n", pathBuffer,
|
||||||
|
subPath);
|
||||||
|
throw status_t(B_BUFFER_OVERFLOW);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
~SubPathAdder()
|
~SubPathAdder()
|
||||||
{
|
{
|
||||||
*fOriginalPathEnd = '\0';
|
*fOriginalPathEnd = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
char* fOriginalPathEnd;
|
char* fOriginalPathEnd;
|
||||||
};
|
};
|
||||||
@@ -668,11 +679,9 @@ PackageWriterImpl::_AddEntry(int dirFD, Entry* entry, const char* fileName,
|
|||||||
{
|
{
|
||||||
bool isImplicitEntry = entry != NULL && entry->IsImplicit();
|
bool isImplicitEntry = entry != NULL && entry->IsImplicit();
|
||||||
|
|
||||||
SubPathAdder pathAdder(pathBuffer, fileName);
|
SubPathAdder pathAdder(fListener, pathBuffer, fileName);
|
||||||
if (!isImplicitEntry) {
|
if (!isImplicitEntry)
|
||||||
fListener->OnEntryAdded(pathBuffer + 1);
|
fListener->OnEntryAdded(pathBuffer);
|
||||||
// pathBuffer + 1 in order to skip leading slash
|
|
||||||
}
|
|
||||||
|
|
||||||
// open the node
|
// open the node
|
||||||
int fd;
|
int fd;
|
||||||
|
|||||||
Reference in New Issue
Block a user