All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dirk Gouders <dirk@gouders.net>
To: Masahiro Yamada <yamada.masahiro@socionext.com>,
	Linux Kbuild mailing list <linux-kbuild@vger.kernel.org>
Cc: Dirk Gouders <dirk@gouders.net>
Subject: [PATCH 1/3] kconfig: avoid assert()-triggered segfaults in xfwrite()
Date: Fri, 22 Jun 2018 21:27:37 +0200	[thread overview]
Message-ID: <20180622192739.5327-2-dirk@gouders.net> (raw)
In-Reply-To: <20180622192739.5327-1-dirk@gouders.net>

xfwrite uses assert() to ensure it does not operate on empty strings.
Two users respect this, expr_print_file_helper() doesn't and causes
segfaults e.g. when the dependency for an empty default string is printed.

Fix this by calling xfwrite with an empty string pattern ("") for
empty strings.

INITRAMFS_SOURCE was one symbol that caused this problem, with this
fix applied the zconfdump() output for this symbol looks as follows:

------------------------------------------------------------------------
config INITRAMFS_SOURCE
  string
  symbol INITRAMFS_SOURCE
  prompt "Initramfs source file(s)" if BLK_DEV_INITRD
  default "" if BLK_DEV_INITRD
  help
This can be either a single cpio archive with a .cpio suffix or a
space-separated list of directories and files for building the
initramfs image.  A cpio archive should contain a filesystem archive
to be used as an initramfs image.  Directories should contain a
filesystem layout to be included in the initramfs image.  Files
should contain entries according to the format described by the
"usr/gen_init_cpio" program in the kernel tree.

When multiple directories and files are specified then the
initramfs image will be the aggregate of all of them.

See <file:Documentation/early-userspace/README> for more details.

If you are not sure, leave it blank.
------------------------------------------------------------------------

Signed-off-by: Dirk Gouders <dirk@gouders.net>
---
 scripts/kconfig/expr.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/scripts/kconfig/expr.c b/scripts/kconfig/expr.c
index e1a39e90841d..e064bf4c2881 100644
--- a/scripts/kconfig/expr.c
+++ b/scripts/kconfig/expr.c
@@ -1231,7 +1231,10 @@ void expr_print(struct expr *e,
 
 static void expr_print_file_helper(void *data, struct symbol *sym, const char *str)
 {
-	xfwrite(str, strlen(str), 1, data);
+	if (*str != '\0')
+		xfwrite(str, strlen(str), 1, data);
+	else
+		xfwrite("\"\"", 2, 1, data);
 }
 
 void expr_fprint(struct expr *e, FILE *out)
-- 
2.13.6


  reply	other threads:[~2018-06-22 19:28 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-22 19:27 [PATCH 0/3] Fixes concerning zconfdump() Dirk Gouders
2018-06-22 19:27 ` Dirk Gouders [this message]
2018-06-27 16:29   ` [PATCH 1/3] kconfig: avoid assert()-triggered segfaults in xfwrite() Masahiro Yamada
2018-06-27 19:23     ` Dirk Gouders
2018-06-29  9:12       ` [PATCH 0/2] kconfig: expr_print(): print constant symbols within quotes Dirk Gouders
2018-06-29  9:12         ` [PATCH v2 1/2] " Dirk Gouders
2018-06-29  9:12         ` [PATCH 2/2] kconfig: fix comment for symbol flag SYMBOL_AUTO Dirk Gouders
2018-07-02 15:14           ` Masahiro Yamada
2018-07-03  7:32             ` Dirk Gouders
2018-07-03  7:51               ` Masahiro Yamada
2018-07-03  9:37                 ` Dirk Gouders
2018-07-03 12:43                   ` [PATCH v3] kconfig: rename SYMBOL_AUTO to SYMBOL_NO_WRITE Dirk Gouders
2018-07-06  2:54                     ` Masahiro Yamada
2018-07-03  9:10             ` [PATCH v2] kconfig: fix comment for symbol flag SYMBOL_AUTO Dirk Gouders
2018-06-22 19:27 ` [PATCH 2/3] kconfig: handle P_SYMBOL in print_symbol() Dirk Gouders
2018-06-27 16:30   ` Masahiro Yamada
2018-06-22 19:27 ` [PATCH 3/3] kconfig: add debugconfig target for debugging purposes Dirk Gouders
2018-07-05  9:31   ` Masahiro Yamada
2018-07-05 11:51     ` Dirk Gouders

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=20180622192739.5327-2-dirk@gouders.net \
    --to=dirk@gouders.net \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=yamada.masahiro@socionext.com \
    /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.