--- Begin Message ---
Subject: |
[PATCH] Handle possible NULL return value of tzalloc. |
Date: |
Tue, 4 Apr 2017 22:04:12 +0200 |
The function tzalloc of gnulib can return NULL. It uses malloc()
internally and forwards its possible NULL value to the caller.
As other gnulib functions rely on that behaviour, it cannot be simply
exchanged with an error-calling malloc alternative.
Take possible NULL return value into account in the programs instead.
Signed-off-by: Tobias Stoeckmann <address@hidden>
---
src/date.c | 2 ++
src/du.c | 2 ++
src/ls.c | 2 ++
src/pr.c | 2 ++
src/stat.c | 6 +++++-
5 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/src/date.c b/src/date.c
index eb7c624e3..b70923c26 100644
--- a/src/date.c
+++ b/src/date.c
@@ -506,6 +506,8 @@ main (int argc, char **argv)
char const *tzstring = getenv ("TZ");
timezone_t tz = tzalloc (tzstring);
+ if (tz == NULL)
+ xalloc_die ();
if (batch_file != NULL)
ok = batch_convert (batch_file, format, tz, tzstring);
diff --git a/src/du.c b/src/du.c
index 8e88b5621..fbddf884f 100644
--- a/src/du.c
+++ b/src/du.c
@@ -909,6 +909,8 @@ main (int argc, char **argv)
? XARGMATCH ("--time", optarg, time_args, time_types)
: time_mtime);
localtz = tzalloc (getenv ("TZ"));
+ if (!localtz)
+ xalloc_die ();
break;
case TIME_STYLE_OPTION:
diff --git a/src/ls.c b/src/ls.c
index 73498181e..7e5e9077c 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -1486,6 +1486,8 @@ main (int argc, char **argv)
}
localtz = tzalloc (getenv ("TZ"));
+ if (localtz == NULL)
+ xalloc_die ();
format_needs_stat = sort_type == sort_time || sort_type == sort_size
|| format == long_format
diff --git a/src/pr.c b/src/pr.c
index 4580c5c78..533286453 100644
--- a/src/pr.c
+++ b/src/pr.c
@@ -1062,6 +1062,8 @@ main (int argc, char **argv)
: "%Y-%m-%d %H:%M");
localtz = tzalloc (getenv ("TZ"));
+ if (localtz == NULL)
+ xalloc_die ();
/* Now we can set a reasonable initial value: */
if (first_page_number == 0)
diff --git a/src/stat.c b/src/stat.c
index d085cd059..d77fbbb3d 100644
--- a/src/stat.c
+++ b/src/stat.c
@@ -589,7 +589,11 @@ human_time (struct timespec t)
+ sizeof "-MM-DD HH:MM:SS.NNNNNNNNN +"];
static timezone_t tz;
if (!tz)
- tz = tzalloc (getenv ("TZ"));
+ {
+ tz = tzalloc (getenv ("TZ"));
+ if (!tz)
+ xalloc_die ();
+ }
struct tm tm;
int ns = t.tv_nsec;
if (localtime_rz (tz, &t.tv_sec, &tm))
--
2.12.2
--- End Message ---
--- Begin Message ---
Subject: |
Re: bug#26364: [PATCH] Handle possible NULL return value of tzalloc. |
Date: |
Wed, 5 Apr 2017 14:38:03 -0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 |
On 04/04/2017 11:04 PM, Tobias Stöckmann wrote:
Please close the report and sorry for the noise.
No problem, closing.
--- End Message ---