agent: Use "ll" length specifier when time_t is larger.
authorNIIBE Yutaka <gniibe@fsij.org>
Mon, 10 Apr 2017 06:04:57 +0000 (15:04 +0900)
committerNIIBE Yutaka <gniibe@fsij.org>
Mon, 10 Apr 2017 06:04:57 +0000 (15:04 +0900)
* agent/command.c (cmd_keytocard): Use KEYTOCARD_TIMESTAMP_FORMAT.

--

On a big-endian 32-bit platform which uses 64-bit time_t, it might go
wrong.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
agent/command.c

index 1f8f7c2..ab6d7eb 100644 (file)
@@ -2477,6 +2477,12 @@ cmd_delete_key (assuan_context_t ctx, char *line)
 
 
 \f
+#if SIZEOF_TIME_T > SIZEOF_UNSIGNED_LONG
+#define KEYTOCARD_TIMESTAMP_FORMAT "(10:created-at10:%010llu))"
+#else
+#define KEYTOCARD_TIMESTAMP_FORMAT "(10:created-at10:%010lu))"
+#endif
+
 static const char hlp_keytocard[] =
   "KEYTOCARD [--force] <hexstring_with_keygrip> <serialno> <id> <timestamp>\n"
   "\n";
@@ -2580,7 +2586,7 @@ cmd_keytocard (assuan_context_t ctx, char *line)
   gcry_sexp_release (s_skey);
   keydatalen--;                        /* Decrement for last '\0'.  */
   /* Add timestamp "created-at" in the private key */
-  snprintf (keydata+keydatalen-1, 30, "(10:created-at10:%010lu))", timestamp);
+  snprintf (keydata+keydatalen-1, 30, KEYTOCARD_TIMESTAMP_FORMAT, timestamp);
   keydatalen += 10 + 19 - 1;
   err = divert_writekey (ctrl, force, serialno, id, keydata, keydatalen);
   xfree (keydata);