diff --git a/headers/private/app/LinkSender.h b/headers/private/app/LinkSender.h index 182a4a5ad1..50b1592052 100644 --- a/headers/private/app/LinkSender.h +++ b/headers/private/app/LinkSender.h @@ -31,7 +31,7 @@ class LinkSender { status_t Flush(bigtime_t timeout = B_INFINITE_TIMEOUT, bool needsReply = false); status_t Attach(const void *data, size_t size); - status_t AttachString(const char *string, int32 length = -1); + status_t AttachString(const char *string, int32 maxLength = -1); template status_t Attach(const Type& data) { return Attach(&data, sizeof(Type)); diff --git a/src/kits/app/LinkSender.cpp b/src/kits/app/LinkSender.cpp index 57f25cb804..1b65d8349f 100644 --- a/src/kits/app/LinkSender.cpp +++ b/src/kits/app/LinkSender.cpp @@ -28,6 +28,7 @@ # define STRACE(x) ; #endif +static const size_t kMaxStringSize = 4096; static const size_t kWatermark = kInitialBufferSize - 24; // if a message is started after this mark, the buffer is flushed automatically @@ -160,8 +161,15 @@ LinkSender::AttachString(const char *string, int32 length) if (string == NULL) string = ""; - if (length == -1) - length = strlen(string); + size_t maxLength = strlen(string); + if (length == -1) { + length = (int32)maxLength; + + // we should report an error here + if (maxLength > kMaxStringSize) + length = 0; + } else if (length > (int32)maxLength) + length = maxLength; status_t status = Attach(length); if (status < B_OK)