From 9a4d2c6b1c2c56c38ce6078b988022b3eb4a310e Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Sun, 13 Mar 2016 14:25:09 -0400 Subject: [PATCH] (fix) properly null-terminate IS8601-formatted dates (fixes #3539) --- NEWS | 1 + SoObjects/SOGo/NSCalendarDate+SOGo.m | 23 ++++++++++++----------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/NEWS b/NEWS index a2b9d7cf5..de0b4aa4c 100644 --- a/NEWS +++ b/NEWS @@ -12,6 +12,7 @@ Bug fixes - [web] fixed display of ghosts when dragging events - [web] fixed management of mail labels in Preferences module - [web] respect super user privileges to create in any calendar and addressbook + - [web] properly null-terminate IS8601-formatted dates (#3539) 3.0.2 (2016-03-04) ------------------ diff --git a/SoObjects/SOGo/NSCalendarDate+SOGo.m b/SoObjects/SOGo/NSCalendarDate+SOGo.m index 5a48d681d..dc9ba8b4c 100644 --- a/SoObjects/SOGo/NSCalendarDate+SOGo.m +++ b/SoObjects/SOGo/NSCalendarDate+SOGo.m @@ -116,31 +116,32 @@ static NSString *rfc822Months[] = {@"", @"Jan", @"Feb", @"Mar", @"Apr", - (NSString *) iso8601DateString { - char buf[22]; - int timeZoneHourShift, timeZoneMinuteShift, tzSeconds; NSNumber *day, *month, *year, *hour, *minute; + int timeZoneHourShift, timeZoneMinuteShift, tzSeconds; + char buf[23]; day = [NSNumber numberWithInt: [self dayOfMonth]]; month = [NSNumber numberWithInt: [self monthOfYear]]; year = [NSNumber numberWithInt: [self yearOfCommonEra]]; hour = [NSNumber numberWithInt: [self hourOfDay]]; minute = [NSNumber numberWithInt: [self minuteOfHour]]; + memset(buf, 0, 23); tzSeconds = [[self timeZone] secondsFromGMT]; timeZoneHourShift = (tzSeconds / 3600); tzSeconds -= timeZoneHourShift * 3600; timeZoneMinuteShift = tzSeconds / 60; - sprintf(buf, "%04d-%02d-%02dT%02d:%02d%+.2d:%02d", - [year intValue], - [month intValue], - [day intValue], - [hour intValue], - [minute intValue], - timeZoneHourShift, - timeZoneMinuteShift); + snprintf(buf, 23, "%04d-%02d-%02dT%02d:%02d%+.2d:%02d", + [year intValue], + [month intValue], + [day intValue], + [hour intValue], + [minute intValue], + timeZoneHourShift, + timeZoneMinuteShift); - return [NSString stringWithCString:buf]; + return [NSString stringWithCString: buf]; } #define secondsOfDistantFuture 1073741823.0