[ libetpan-Bugs-2892730 ] Crash on Windows during message_id computation

"SourceForge.net" <[email protected]> Mon, 05 Apr 2010 13:20:02 +0000
Newsgroups gmane.mail.libetpan.user
Message-ID <[email protected]>
Bugs item #2892730, was opened at 2009-11-05 18:10
Message generated for change (Settings changed) made by hoa
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=429696&aid=2892730&group_id=41064

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: other
Group: Latest stable - libEtPan!
>Status: Closed
Resolution: Fixed
Priority: 5
Private: No
Submitted By: Sergey Perminov (perminov)
Assigned to: Nobody/Anonymous (nobody)
Summary: Crash on Windows during message_id computation

Initial Comment:
low-level/imf/mailimf_types_helper.c file, mailimf_get_message_id function:

 1271 char * mailimf_get_message_id(void)
 1272 {
 1273   char id[MAX_MESSAGE_ID];
 1274   time_t now;
 1275   char name[MAX_MESSAGE_ID];
 1276   long value;
 1277 
 1278   now = time(NULL);
 1279   value = random();
 1280 
 1281   gethostname(name, MAX_MESSAGE_ID);
 1282   snprintf(id, MAX_MESSAGE_ID, "etPan.%lx.%lx.%x@%s",
 1283 	   now, value, getpid(), name);
 1284 
 1285   return strdup(id);
 1286 }

On Windows time_t is 8 byte long type.
In case you pass 8 instead of 4 bytes into snprintf function, 
windows runtime crashes with "memory access violation"

Environment:
Compiled under VS2008SP1

As a fix it's possible to use long instead of time_t:

--- mailimf_types_helper.c.orig	2009-11-05 21:06:34.000000000 +0300
+++ mailimf_types_helper.c	2009-11-05 21:07:08.000000000 +0300
@@ -1271,11 +1271,11 @@
 char * mailimf_get_message_id(void)
 {
   char id[MAX_MESSAGE_ID];
-  time_t now;
+  long now;
   char name[MAX_MESSAGE_ID];
   long value;
 
-  now = time(NULL);
+  now = (long)time(NULL);
   value = random();
 
   gethostname(name, MAX_MESSAGE_ID);



----------------------------------------------------------------------

Comment By: DINH V. Hoa (hoa)
Date: 2009-12-19 02:02

Message:
fixed inlibetpan-0.58cvs11

----------------------------------------------------------------------

Comment By: Sergey Perminov (perminov)
Date: 2009-11-06 12:19

Message:
Define will not work if it's defined in source/header.
It's only possible to switch to 32bit from command line parameter,
i.e. like C:\>cl Source1.cpp /D_USE_32BIT_TIME_T

As for me, I think it's much more dangerous as far as if you are linked
with some another library (like openssl)
 which uses 64bit time_t and compiled w/o this option -> behaviour is
unpredictable.

Test is:

C:\>cl Source1.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for
80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

Source1.cpp
Microsoft (R) Incremental Linker Version 9.00.30729.01
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:Source1.exe
Source1.obj

C:\>Source1.exe
SZ :8

C:\>cl Source1.cpp /D_USE_32BIT_TIME_T
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for
80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

Source1.cpp
Microsoft (R) Incremental Linker Version 9.00.30729.01
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:Source1.exe
Source1.obj

C:\>Source1.exe
SZ :4

C:\>



#include <stdio.h>

#ifndef _USE_32BIT_TIME_T 
  #define _USE_32BIT_TIME_T 32
#endif

int main (void) {
  printf("SZ :%d\n", sizeof(time_t));
  return 1;
}

----------------------------------------------------------------------

Comment By: Sebastien Marinier (smarinier)
Date: 2009-11-06 09:59

Message:
I think it would be better to allow all the time_t for the library to
"work" (until 18 Jan 2038 ;) ) and to handle the 64 bits mode also.

This would give, according to me, in build-windows/StdAfx.h  : 

#if !defined(_WIN64)
#  define _USE_32BIT_TIME_T
#endif

Could you check this ?

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=429696&aid=2892730&group_id=41064

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev