Windows: Use secure ctime and strncpy in afs_ctime
authorJeffrey Altman <jaltman@secure-endpoints.com>
Sun, 6 Sep 2009 22:47:54 +0000 (18:47 -0400)
committerJeffrey Altman <jaltman|account-1000011@unknown>
Tue, 8 Sep 2009 17:56:00 +0000 (10:56 -0700)
Microsoft compilers version 1500 and above provide secure
versions of ctime and strncpy.  Use them in afs_ctime.

Reviewed-on: http://gerrit.openafs.org/408
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Tested-by: Asanka Herath <asanka@secure-endpoints.com>
Reviewed-by: Asanka Herath <asanka@secure-endpoints.com>
Tested-by: Derrick Brashear <shadow@dementia.org>
Reviewed-by: Jeffrey Altman <jaltman@openafs.org>

src/util/afsutil.h

index dc587a6..177a3f2 100644 (file)
@@ -91,8 +91,15 @@ extern char *vctime(const time_t * atime);
 #else /* AFS_PTHREAD_ENV && !AFS_NT40_ENV */
 static_inline char *
 afs_ctime(const time_t *C, char *B, size_t S) {
+#if !defined(AFS_NT40_ENV) || (_MSC_VER < 1500)
     strncpy(B, ctime(C), (S-1));
     B[S-1] = '\0';
+#else
+    char buf[32];
+    if (ctime_s(buf, sizeof(buf), C) ||
+        strncpy_s(B, S, buf, _TRUNCATE)
+         B[0] = '\0';
+#endif
     return B;
 }
 #endif /* AFS_PTHREAD_ENV && !AFS_NT40_ENV */