From f46e077c5f39f87912b1d09cd02d31860f7d6360 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Wed, 9 Nov 2005 18:28:13 +0000 Subject: [PATCH] Changed the meaning of the second parameter in AttachString(): it's now the maximum length, not the length of the string. Introduced a maximal string length that may be sent at once. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14799 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/app/LinkSender.h | 2 +- src/kits/app/LinkSender.cpp | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) 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)