All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
To: lttng-dev@lists.lttng.org
Cc: jgalar@efficios.com
Subject: [PATCH lttng-tools 1/2] Fix: syscall_table_nb_entry invalid value when no syscalls TPs are defined
Date: Mon, 13 Mar 2017 18:11:48 -0400	[thread overview]
Message-ID: <1489443109-12380-1-git-send-email-jonathan.rajotte-julien__31243.389848578$1489443149$gmane$org@efficios.com> (raw)

fscanf on an empty file returns directly without assigning value to
'index' leading to assigning the value of an uninitialized variable to
syscall_table_nb_entry. This can result in memory allocation problems
when listing syscalls on 'lttng list --kernel --syscall'[1][2].

Fixes #1091

[1] https://bugs.lttng.org/issues/1091
[2] https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1671063/

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
---
 src/bin/lttng-sessiond/syscall.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/bin/lttng-sessiond/syscall.c b/src/bin/lttng-sessiond/syscall.c
index 6ee38bd..c21e4d8 100644
--- a/src/bin/lttng-sessiond/syscall.c
+++ b/src/bin/lttng-sessiond/syscall.c
@@ -16,6 +16,8 @@
  */
 
 #define _LGPL_SOURCE
+#include <stdbool.h>
+
 #include <common/bitfield.h>
 #include <common/common.h>
 #include <common/kernel-ctl/kernel-ctl.h>
@@ -43,7 +45,8 @@ int syscall_init_table(void)
 	size_t nbmem;
 	FILE *fp;
 	/* Syscall data from the kernel. */
-	size_t index;
+	size_t index = 0;
+	bool at_least_one_syscall = false;
 	uint32_t bitness;
 	char name[SYSCALL_NAME_LEN];
 
@@ -76,7 +79,8 @@ int syscall_init_table(void)
 				name = %" XSTR(SYSCALL_NAME_LEN) "[^;]; \
 				bitness = %u; };\n",
 				&index, name, &bitness) == 3) {
-		if (index >= nbmem ) {
+		at_least_one_syscall = true;
+		if (index >= nbmem) {
 			struct syscall *new_list;
 			size_t new_nbmem;
 
@@ -123,7 +127,10 @@ int syscall_init_table(void)
 		*/
 	}
 
-	syscall_table_nb_entry = index;
+	/* Index start at 0. */
+	if (at_least_one_syscall) {
+		syscall_table_nb_entry = index + 1;
+	}
 
 	ret = 0;
 
-- 
2.7.4

_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

             reply	other threads:[~2017-03-13 22:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-13 22:11 Jonathan Rajotte [this message]
     [not found] <1489443109-12380-1-git-send-email-jonathan.rajotte-julien@efficios.com>
2017-03-14  1:12 ` [PATCH lttng-tools 1/2] Fix: syscall_table_nb_entry invalid value when no syscalls TPs are defined Mathieu Desnoyers
     [not found] ` <463034182.4458.1489453949213.JavaMail.zimbra@efficios.com>
2017-03-14  1:28   ` Mathieu Desnoyers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='1489443109-12380-1-git-send-email-jonathan.rajotte-julien__31243.389848578$1489443149$gmane$org@efficios.com' \
    --to=jonathan.rajotte-julien@efficios.com \
    --cc=jgalar@efficios.com \
    --cc=lttng-dev@lists.lttng.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.