Skip to content

Commit dfbf1cf

Browse files
committed
Restructure sandbox report for the sake of truncation
1 parent 2e5eb5f commit dfbf1cf

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

Public/Src/Engine/Processes/SandboxConnectionLinuxDetours.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ private void ProcessBytes((PooledObjectWrapper<byte[]> wrapper, int length) item
384384
var message = s_encoding.GetString(item.wrapper.Instance, index: 0, count: item.length).AsSpan().TrimEnd('\n');
385385

386386
// parse the message, consuming the span field by field. The format is:
387-
// "%s|%d|%d|%d|%d|%d|%d|%s|%d\n", __progname, getpid(), access, status, explicitLogging, err, opcode, reportPath, isDirectory
387+
// "%s|%d|%d|%d|%d|%d|%d|%d|%s\n", __progname, getpid(), access, status, explicitLogging, err, opcode, isDirectory, reportPath
388388
var restOfMessage = message;
389389
_ = nextField(restOfMessage, out restOfMessage); // ignore progname
390390
var pid = AssertInt(nextField(restOfMessage, out restOfMessage));
@@ -393,8 +393,8 @@ private void ProcessBytes((PooledObjectWrapper<byte[]> wrapper, int length) item
393393
var explicitlogging = AssertInt(nextField(restOfMessage, out restOfMessage));
394394
var err = AssertInt(nextField(restOfMessage, out restOfMessage));
395395
var opCode = AssertInt(nextField(restOfMessage, out restOfMessage));
396-
var path = nextField(restOfMessage, out restOfMessage);
397396
var isDirectory = AssertInt(nextField(restOfMessage, out restOfMessage));
397+
var path = nextField(restOfMessage, out restOfMessage);
398398
Contract.Assert(restOfMessage.IsEmpty); // We should have reached the end of the message
399399

400400
// ignore accesses to libDetours.so, because we injected that library

Public/Src/Sandbox/Linux/bxl_observer.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,11 @@ bool BxlObserver::SendReport(const AccessReport &report, bool isDebugMessage, bo
362362
}
363363
else
364364
{
365-
// The debug message was truncated. Let's crop the debug message so it fits
366-
int truncatedSize = PATH_MAX - (numWritten - maxMessageLength);
365+
// The report couldn't be fully built for a debug message. Let's crop the message so it fits.
366+
// We calculate the maximum size allowed, considering that 'path' is the last component of the
367+
// message (plus the \n that ends any report, hence the -1), so it's the last thing
368+
// we tried to write when hitting the size limit.
369+
int truncatedSize = PATH_MAX - (numWritten - maxMessageLength) - 1;
367370
char truncatedMessage[truncatedSize] = {0};
368371

369372
// Let's leave an ending \0

Public/Src/Sandbox/Linux/bxl_observer.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,11 @@ class BxlObserver final
328328
// Builds the report to be sent over the FIFO in the given buffer
329329
inline int BuildReport(char* buffer, int maxMessageLength, const AccessReport &report, const char *path)
330330
{
331+
// Note: when adding new fields, always leave 'path' as the last component of this message
332+
// This is for the sake of the arithmetic when truncating debug messages, where this assumption is made (see SendReport).
331333
return snprintf(
332-
buffer, maxMessageLength, "%s|%d|%d|%d|%d|%d|%d|%s|%d\n",
333-
__progname, report.pid <= 0 ? getpid() : report.pid, report.requestedAccess, report.status, report.reportExplicitly, report.error, report.operation, path, report.isDirectory);
334+
buffer, maxMessageLength, "%s|%d|%d|%d|%d|%d|%d|%d|%s\n",
335+
__progname, report.pid <= 0 ? getpid() : report.pid, report.requestedAccess, report.status, report.reportExplicitly, report.error, report.operation, report.isDirectory, path);
334336
}
335337

336338
static BxlObserver *sInstance;

0 commit comments

Comments
 (0)