mailarchive of the ptxdist mailing list
 help / color / mirror / Atom feed
From: Alexander Aring <alex.aring@gmail.com>
To: ptxdist@pengutronix.de
Cc: Alexander Aring <alex.aring@gmail.com>
Subject: [ptxdist] [PATCH 2/2] genimage: add workaround to work with glibc 2.22
Date: Sun, 23 Aug 2015 15:56:58 +0200	[thread overview]
Message-ID: <1440338218-18404-2-git-send-email-alex.aring@gmail.com> (raw)
In-Reply-To: <1440338218-18404-1-git-send-email-alex.aring@gmail.com>

This patch adds a workaround for check if value argument of setenv is
null. In all glibc versions setenv(..., NULL, ...) ends in an undef
behaviour, since glibc 2.22 it will end in a core dump.

This is a workaround because it adds to every setenv a null check. I
think some setenv are optional and some need to be set like name. Maybe
we should make then a clear upstream patch which checks on this. I
currently don't know which setenv is optional and which not. In my case
of creating vfat image it seems some of them are optional like
IMAGEMOUNTPOINT.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
 ...ge-add-wrapper-for-handling-setenv-.-NULL.patch | 68 ++++++++++++++++++++++
 patches/genimage-7/series                          |  4 ++
 2 files changed, 72 insertions(+)
 create mode 100644 patches/genimage-7/0001-genimage-add-wrapper-for-handling-setenv-.-NULL.patch
 create mode 100644 patches/genimage-7/series

diff --git a/patches/genimage-7/0001-genimage-add-wrapper-for-handling-setenv-.-NULL.patch b/patches/genimage-7/0001-genimage-add-wrapper-for-handling-setenv-.-NULL.patch
new file mode 100644
index 0000000..79a2c3e
--- /dev/null
+++ b/patches/genimage-7/0001-genimage-add-wrapper-for-handling-setenv-.-NULL.patch
@@ -0,0 +1,68 @@
+From: Alexander Aring <alex.aring@gmail.com>
+Date: Sun, 23 Aug 2015 13:17:38 +0200
+Subject: [PATCH] genimage: add wrapper for handling setenv(..., NULL, ...)
+
+This patch adds a wrapper when calling setenv(..., NULL, ...) to a
+no-op. Since glibc 2.22 this will end in a core dump.
+
+Signed-off-by: Alexander Aring <alex.aring@gmail.com>
+---
+ genimage.c | 29 ++++++++++++++++++++---------
+ 1 file changed, 20 insertions(+), 9 deletions(-)
+
+diff --git a/genimage.c b/genimage.c
+index e80127a2fbb9..9f60cc092eb4 100644
+--- a/genimage.c
++++ b/genimage.c
+@@ -239,6 +239,17 @@ static int image_generate(struct image *image)
+ 	return 0;
+ }
+ 
++/*
++ * Simple wrapper for setenv which doesn't run setenv if value == NULL
++ */
++static int image_setenv(const char *name, const char *value, int overwrite)
++{
++	if (!value)
++		return 0;
++	else
++		return setenv(name, value, overwrite);
++}
++
+ static LIST_HEAD(flashlist);
+ 
+ static int parse_flashes(cfg_t *cfg)
+@@ -598,10 +609,10 @@ int main(int argc, char *argv[])
+ 		if (ret)
+ 			goto err_out;
+ 	}
+-	setenv("OUTPUTPATH", imagepath(), 1);
+-	setenv("INPUTPATH", inputpath(), 1);
+-	setenv("ROOTPATH", rootpath(), 1);
+-	setenv("TMPPATH", tmppath(), 1);
++	image_setenv("OUTPUTPATH", imagepath(), 1);
++	image_setenv("INPUTPATH", inputpath(), 1);
++	image_setenv("ROOTPATH", rootpath(), 1);
++	image_setenv("TMPPATH", tmppath(), 1);
+ 
+ 	ret = systemp(NULL, "mkdir -p %s", imagepath());
+ 	if (ret)
+@@ -613,13 +624,13 @@ int main(int argc, char *argv[])
+ 
+ 	list_for_each_entry(image, &images, list) {
+ 		char *sizestr;
+-		setenv("IMAGE", image->file, 1);
+-		setenv("IMAGEOUTFILE", imageoutfile(image), 1);
+-		setenv("IMAGENAME", image->name, 1);
++		image_setenv("IMAGE", image->file, 1);
++		image_setenv("IMAGEOUTFILE", imageoutfile(image), 1);
++		image_setenv("IMAGENAME", image->name, 1);
+ 		asprintf(&sizestr, "%lld", image->size);
+-		setenv("IMAGESIZE", sizestr, 1);
++		image_setenv("IMAGESIZE", sizestr, 1);
+ 		free(sizestr);
+-		setenv("IMAGEMOUNTPOINT", image->mountpoint, 1);
++		image_setenv("IMAGEMOUNTPOINT", image->mountpoint, 1);
+ 		ret = image_generate(image);
+ 		if (ret) {
+ 			image_error(image, "failed to generate %s\n", image->file);
diff --git a/patches/genimage-7/series b/patches/genimage-7/series
new file mode 100644
index 0000000..7e934ff
--- /dev/null
+++ b/patches/genimage-7/series
@@ -0,0 +1,4 @@
+# generated by git-ptx-patches
+#tag:base --start-number 1
+0001-genimage-add-wrapper-for-handling-setenv-.-NULL.patch
+# 1d1a2661aa1e8827ec74d7a3aa9b9793  - git-ptx-patches magic
-- 
2.5.0


-- 
ptxdist mailing list
ptxdist@pengutronix.de

  reply	other threads:[~2015-08-23 13:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-23 13:56 [ptxdist] [PATCH 1/2] wpan-tools: version bump 0.4 -> 0.5 Alexander Aring
2015-08-23 13:56 ` Alexander Aring [this message]
2015-08-25 12:41   ` [ptxdist] [PATCH 2/2] genimage: add workaround to work with glibc 2.22 Alexander Aring

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=1440338218-18404-2-git-send-email-alex.aring@gmail.com \
    --to=alex.aring@gmail.com \
    --cc=ptxdist@pengutronix.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox