[PATCH] fix segfault with invalid time structures
Mike Frysinger
vapier at gentoo.org
Sat Apr 19 20:28:07 UTC 2008
From: Harald van Dijk <truedfx at gentoo.org>
If you strace a function that makes an invalid call with a time structure
set to NULL, strace will bomb.
Signed-off-by: Harald van Dijk <truedfx at gentoo.org>
Signed-off-by: Mike Frysinger <vapier at gentoo.org>
---
file.c | 10 +++++++---
1 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/file.c b/file.c
index b299961..316fde9 100644
--- a/file.c
+++ b/file.c
@@ -687,9 +687,13 @@ time_t t;
return buf;
}
tmp = localtime(&t);
- sprintf(buf, "%02d/%02d/%02d-%02d:%02d:%02d",
- tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
- tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
+ if (tmp == NULL)
+ snprintf(buf, sizeof buf, "%lu",
+ (unsigned long) t);
+ else
+ sprintf(buf, "%02d/%02d/%02d-%02d:%02d:%02d",
+ tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
+ tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
return buf;
}
--
1.5.5
More information about the Strace-devel
mailing list