You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2017/08/09 16:23:22 UTC
[trafficserver] branch master updated: Cleanup / correct buffer
sizes for UUIDs
This is an automated email from the ASF dual-hosted git repository.
zwoop pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new 84865cc Cleanup / correct buffer sizes for UUIDs
84865cc is described below
commit 84865cc8778e11c93ff3b658c6699631e4962c08
Author: Leif Hedstrom <zw...@apache.org>
AuthorDate: Sat Jul 22 08:45:06 2017 +0200
Cleanup / correct buffer sizes for UUIDs
This also makes sure the marshalled string is the length of the
UUID-SMID string properly, which means doing the snprintf() both
when calculating the length, as well as when marshalling. Slightly
inefficient, but the alternative is klunkier (log10 etc.).
---
doc/developer-guide/api/functions/TSUuidCreate.en.rst | 5 +++--
lib/ts/apidefs.h.in | 2 +-
proxy/InkAPI.cc | 2 +-
proxy/logging/LogAccessHttp.cc | 18 ++++++++----------
4 files changed, 13 insertions(+), 14 deletions(-)
diff --git a/doc/developer-guide/api/functions/TSUuidCreate.en.rst b/doc/developer-guide/api/functions/TSUuidCreate.en.rst
index 2239184..9f91650 100644
--- a/doc/developer-guide/api/functions/TSUuidCreate.en.rst
+++ b/doc/developer-guide/api/functions/TSUuidCreate.en.rst
@@ -88,8 +88,9 @@ object, but it does not need to be previously initialized.
Finally, :func:`TSClientRequestUuidGet` can be used to extract
the client request uuid from a transaction. The output buffer must be of
-sufficient length, minimum of ``TS_CRUUID_STRING_LEN``. This produces the same
-string as the log tag %<cruuid> generates.
+sufficient length, minimum of ``TS_CRUUID_STRING_LEN`` + 1 bytes. This
+produces the same string as the log tag %<cruuid> generates, and it will
+be NULL terminated.
Return Values
=============
diff --git a/lib/ts/apidefs.h.in b/lib/ts/apidefs.h.in
index eb69a70..72beeaa 100644
--- a/lib/ts/apidefs.h.in
+++ b/lib/ts/apidefs.h.in
@@ -1204,7 +1204,7 @@ typedef enum {
} TSUuidVersion;
#define TS_UUID_STRING_LEN 36
-#define TS_CRUUID_STRING_LEN (TS_UUID_STRING_LEN + 20 + 1) /* UUID-len + len(int64_t) + '-' */
+#define TS_CRUUID_STRING_LEN (TS_UUID_STRING_LEN + 19 + 1) /* UUID-len + len(uint64_t) + '-' */
typedef struct tsapi_uuid *TSUuid;
#ifdef __cplusplus
diff --git a/proxy/InkAPI.cc b/proxy/InkAPI.cc
index 644ca53..4758b62 100644
--- a/proxy/InkAPI.cc
+++ b/proxy/InkAPI.cc
@@ -9287,7 +9287,7 @@ TSClientRequestUuidGet(TSHttpTxn txnp, char *uuid_str)
const char *machine = (char *)Machine::instance()->uuid.getString();
int len;
- len = snprintf(uuid_str, TS_CRUUID_STRING_LEN, "%s-%" PRId64 "", machine, sm->sm_id);
+ len = snprintf(uuid_str, TS_CRUUID_STRING_LEN + 1, "%s-%" PRId64 "", machine, sm->sm_id);
if (len > TS_CRUUID_STRING_LEN) {
return TS_ERROR;
}
diff --git a/proxy/logging/LogAccessHttp.cc b/proxy/logging/LogAccessHttp.cc
index a85acbe..28ff3d0 100644
--- a/proxy/logging/LogAccessHttp.cc
+++ b/proxy/logging/LogAccessHttp.cc
@@ -788,20 +788,18 @@ LogAccessHttp::marshal_client_req_id(char *buf)
int
LogAccessHttp::marshal_client_req_uuid(char *buf)
{
- if (buf) {
- char str[TS_CRUUID_STRING_LEN + 1];
- const char *uuid = (char *)Machine::instance()->uuid.getString();
- int len;
+ char str[TS_CRUUID_STRING_LEN + 1];
+ const char *uuid = Machine::instance()->uuid.getString();
+ int len = snprintf(str, sizeof(str), "%s-%" PRId64 "", uuid, m_http_sm->sm_id);
- len = snprintf(str, sizeof(str), "%s-%" PRId64 "", uuid, m_http_sm->sm_id);
- ink_assert(len < (int)sizeof(str));
+ ink_assert(len <= TS_CRUUID_STRING_LEN);
+ len = round_strlen(len + 1);
- len = round_strlen(len + 1);
- marshal_str(buf, str, len);
- return len;
+ if (buf) {
+ marshal_str(buf, str, len); // This will pad the remaning bytes properly ...
}
- return round_strlen(TS_CRUUID_STRING_LEN + 1);
+ return len;
}
/*-------------------------------------------------------------------------
--
To stop receiving notification emails like this one, please contact
['"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>'].