You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
2.0 KiB

  1. From: Huangbin Zhan <zhanhb88@gmail.com>
  2. Date: Tue, 9 Nov 2021 23:05:55 +0800
  3. Subject: [PATCH] hsts.c: fix timestamp reading and writing.
  4. Always get zero time on big endian 32bit OS with 64bit time_t such as mips_24kc_musl.
  5. ---
  6. src/hsts.c | 16 ++++++++--------
  7. 1 file changed, 8 insertions(+), 8 deletions(-)
  8. --- a/src/hsts.c
  9. +++ b/src/hsts.c
  10. @@ -280,7 +280,7 @@ hsts_read_database (hsts_store_t store,
  11. char host[256];
  12. int port;
  13. - time_t created, max_age;
  14. + uintmax_t created, max_age;
  15. int include_subdomains;
  16. func = (merge_with_existing_entries ? hsts_store_merge : hsts_new_entry);
  17. @@ -293,15 +293,15 @@ hsts_read_database (hsts_store_t store,
  18. if (*p == '#')
  19. continue;
  20. - items_read = sscanf (p, "%255s %d %d %lu %lu",
  21. + items_read = sscanf (p, "%255s %d %d %"SCNuMAX" %"SCNuMAX,
  22. host,
  23. &port,
  24. &include_subdomains,
  25. - (unsigned long *) &created,
  26. - (unsigned long *) &max_age);
  27. + &created,
  28. + &max_age);
  29. if (items_read == 5)
  30. - func (store, host, port, created, max_age, !!include_subdomains);
  31. + func (store, host, port, (time_t) created, (time_t) max_age, !!include_subdomains);
  32. }
  33. xfree (line);
  34. @@ -326,10 +326,10 @@ hsts_store_dump (hsts_store_t store, FIL
  35. struct hsts_kh *kh = (struct hsts_kh *) it.key;
  36. struct hsts_kh_info *khi = (struct hsts_kh_info *) it.value;
  37. - if (fprintf (fp, "%s\t%d\t%d\t%lu\t%lu\n",
  38. + if (fprintf (fp, "%s\t%d\t%d\t%"PRIuMAX"\t%"PRIuMAX"\n",
  39. kh->host, kh->explicit_port, khi->include_subdomains,
  40. - (unsigned long) khi->created,
  41. - (unsigned long) khi->max_age) < 0)
  42. + (uintmax_t) khi->created,
  43. + (uintmax_t) khi->max_age) < 0)
  44. {
  45. logprintf (LOG_ALWAYS, "Could not write the HSTS database correctly.\n");
  46. break;