From: Alexander Aring <alex.aring@gmail.com>
To: ptxdist@pengutronix.de
Subject: Re: [ptxdist] [PATCH 2/2] genimage: add workaround to work with glibc 2.22
Date: Tue, 25 Aug 2015 14:41:06 +0200 [thread overview]
Message-ID: <20150825124100.GA20806@omega> (raw)
In-Reply-To: <1440338218-18404-2-git-send-email-alex.aring@gmail.com>
On Sun, Aug 23, 2015 at 03:56:58PM +0200, Alexander Aring wrote:
> 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);
> ++}
This sould be:
static inline int image_setenv(const char *name, const char *value, int overwrite)
{
return setenv(name, value ? value : "", overwrite);
}
Current solution is 100% broken if generating multiple images in the
below list_for_each_entry loop it will not overwrite the previous
setting.
> ++
> + 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) {
I mean this loop here.
> + 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);
I will not send a v2 until mol's opinion according to that solution.
- Alex
--
ptxdist mailing list
ptxdist@pengutronix.de
prev parent reply other threads:[~2015-08-25 12:41 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 ` [ptxdist] [PATCH 2/2] genimage: add workaround to work with glibc 2.22 Alexander Aring
2015-08-25 12:41 ` Alexander Aring [this message]
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=20150825124100.GA20806@omega \
--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