* [PATCH] btrfs-progs: use reentrant localtime
@ 2013-07-09 16:39 David Sterba
0 siblings, 0 replies; only message in thread
From: David Sterba @ 2013-07-09 16:39 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
localtime may return NULL (when an error is detected eg. after setting
tzname), followed by a segfault when the values is about to be used.
localtime_r works, does not set tzname and does not return NULL.
Signed-off-by: David Sterba <dsterba@suse.cz>
---
btrfs-list.c | 10 ++++++----
cmds-subvolume.c | 10 ++++++----
2 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/btrfs-list.c b/btrfs-list.c
index c3d35de..7fcee19 100644
--- a/btrfs-list.c
+++ b/btrfs-list.c
@@ -1344,10 +1344,12 @@ static void print_subvolume_column(struct root_info *subv,
printf("%llu", subv->top_id);
break;
case BTRFS_LIST_OTIME:
- if (subv->otime)
- strftime(tstr, 256, "%Y-%m-%d %X",
- localtime(&subv->otime));
- else
+ if (subv->otime) {
+ struct tm tm;
+
+ localtime_r(&subv->otime, &tm);
+ strftime(tstr, 256, "%Y-%m-%d %X", &tm);
+ } else
strcpy(tstr, "-");
printf("%s", tstr);
break;
diff --git a/cmds-subvolume.c b/cmds-subvolume.c
index ccb4762..faf05ca 100644
--- a/cmds-subvolume.c
+++ b/cmds-subvolume.c
@@ -898,10 +898,12 @@ static int cmd_subvol_show(int argc, char **argv)
uuid_unparse(get_ri.puuid, uuidparse);
printf("\tParent uuid: \t\t%s\n", uuidparse);
- if (get_ri.otime)
- strftime(tstr, 256, "%Y-%m-%d %X",
- localtime(&get_ri.otime));
- else
+ if (get_ri.otime) {
+ struct tm tm;
+
+ localtime_r(&get_ri.otime, &tm);
+ strftime(tstr, 256, "%Y-%m-%d %X", &tm);
+ } else
strcpy(tstr, "-");
printf("\tCreation time: \t\t%s\n", tstr);
--
1.8.2
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2013-07-09 16:39 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-09 16:39 [PATCH] btrfs-progs: use reentrant localtime David Sterba
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).