sysutils/lttng-tools: fix obtaining HOST_NAME_MAX

Using sysconf(3) API lead to accidental introduction of variable length arrays
(VLA) in the port. Additionally one patch hardcoded 256 as the HOST_NAME_MAX
even though the code doesn't expect an additional byte for the terminating NULL
byte in the struct definition.

Fall back to using _POSIX_HOST_NAME_MAX as the remaining code is not ready for
introducing sysconf(3) as a patch.

Remove #ifdef FreeBSD from our patches.

Bump PORTREVISION to rebuild with the new patch.

Sponsored by:   Fudo Security
Differential Revision:	https://reviews.freebsd.org/D30048
This commit is contained in:
Adam Wolk 2021-04-30 17:16:05 +02:00 committed by Jan Beich
parent 7f746ebb66
commit aa34b0f42f
5 changed files with 47 additions and 28 deletions

View file

@ -2,7 +2,7 @@
PORTNAME= lttng-tools
PORTVERSION= 2.9.3
PORTREVISION= 5
PORTREVISION= 6
CATEGORIES= sysutils
MASTER_SITES= http://lttng.org/files/${PORTNAME}/

View file

@ -1,12 +1,19 @@
--- src/bin/lttng-sessiond/consumer.c.orig 2016-11-29 22:48:37 UTC
+++ src/bin/lttng-sessiond/consumer.c
@@ -635,6 +635,9 @@ int consumer_set_network_uri(struct cons
--- src/bin/lttng-sessiond/consumer.c.orig 2017-01-09 19:26:28 UTC
+++ src/bin/lttng-sessiond/consumer.c
@@ -17,6 +17,7 @@
#define _LGPL_SOURCE
#include <assert.h>
+#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -635,7 +636,7 @@ int consumer_set_network_uri(struct consumer_output *o
{
int ret;
char tmp_path[PATH_MAX];
+#if defined(__FreeBSD__)
+ const size_t HOST_NAME_MAX = sysconf(_SC_HOST_NAME_MAX);
+#endif
char hostname[HOST_NAME_MAX];
- char hostname[HOST_NAME_MAX];
+ char hostname[_POSIX_HOST_NAME_MAX];
struct lttng_uri *dst_uri = NULL;
/* Code flow error safety net. */

View file

@ -1,14 +1,11 @@
--- src/bin/lttng-sessiond/session.h.orig 2016-11-29 22:48:37 UTC
--- src/bin/lttng-sessiond/session.h.orig 2017-01-09 19:26:28 UTC
+++ src/bin/lttng-sessiond/session.h
@@ -60,7 +60,11 @@ struct ltt_session_list {
@@ -60,7 +60,7 @@ struct ltt_session_list {
*/
struct ltt_session {
char name[NAME_MAX];
+#if defined(__FreeBSD__)
+ char hostname[256]; /* Local hostname. */
+#else
char hostname[HOST_NAME_MAX]; /* Local hostname. */
+#endif
- char hostname[HOST_NAME_MAX]; /* Local hostname. */
+ char hostname[_POSIX_HOST_NAME_MAX]; /* Local hostname. */
struct ltt_kernel_session *kernel_session;
struct ltt_ust_session *ust_session;
/*

View file

@ -1,6 +1,6 @@
--- src/bin/lttng-sessiond/ust-metadata.c.orig 2016-11-29 22:48:37 UTC
--- src/bin/lttng-sessiond/ust-metadata.c.orig 2017-01-09 19:26:28 UTC
+++ src/bin/lttng-sessiond/ust-metadata.c
@@ -50,6 +50,7 @@ int _lttng_field_statedump(struct ust_re
@@ -50,6 +50,7 @@ int _lttng_field_statedump(struct ust_registry_session
const struct ustctl_field *fields, size_t nr_fields,
size_t *iter_field, size_t nesting);
@ -16,13 +16,21 @@
static inline
int get_count_order(unsigned int count)
@@ -879,6 +881,9 @@ int ust_metadata_session_statedump(struc
@@ -879,7 +881,7 @@ int ust_metadata_session_statedump(struct ust_registry
char uuid_s[UUID_STR_LEN],
clock_uuid_s[UUID_STR_LEN];
int ret = 0;
+#if defined(__FreeBSD__)
+ const size_t HOST_NAME_MAX = sysconf(_SC_HOST_NAME_MAX);
+#endif
char hostname[HOST_NAME_MAX];
- char hostname[HOST_NAME_MAX];
+ char hostname[_POSIX_HOST_NAME_MAX];
assert(session);
@@ -940,7 +942,7 @@ int ust_metadata_session_statedump(struct ust_registry
hostname[0] = '\0';
ret = gethostname(hostname, sizeof(hostname));
if (ret && errno == ENAMETOOLONG)
- hostname[HOST_NAME_MAX - 1] = '\0';
+ hostname[_POSIX_HOST_NAME_MAX - 1] = '\0';
ret = lttng_metadata_printf(session,
"env {\n"
" hostname = \"%s\";\n"

View file

@ -1,12 +1,19 @@
--- src/bin/lttng/commands/view.c.orig 2016-11-29 22:48:37 UTC
--- src/bin/lttng/commands/view.c.orig 2017-01-09 19:26:28 UTC
+++ src/bin/lttng/commands/view.c
@@ -269,6 +269,9 @@ static char *build_live_path(char *sessi
@@ -17,6 +17,7 @@
#define _LGPL_SOURCE
#include <popt.h>
+#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -269,7 +270,7 @@ static char *build_live_path(char *session_name)
{
int ret;
char *path = NULL;
+#if defined(__FreeBSD__)
+ const size_t HOST_NAME_MAX = sysconf(_SC_HOST_NAME_MAX);
+#endif
char hostname[HOST_NAME_MAX];
- char hostname[HOST_NAME_MAX];
+ char hostname[_POSIX_HOST_NAME_MAX];
ret = gethostname(hostname, sizeof(hostname));
if (ret < 0) {