Rewrite some code to workaround strict aliasing rule violation for older compilers
[hashcat.git] / src / shared.c
index e972b7d..86ddc01 100644 (file)
@@ -2387,7 +2387,7 @@ int tty_fix()
 }
 #endif
 
-#ifdef DARWIN
+#if defined(DARWIN) || defined(__FreeBSD__)
 static struct termios savemodes;
 static int havemodes = 0;
 
@@ -3489,7 +3489,9 @@ int hm_set_fanspeed_with_device_id_nvapi (const uint device_id, const int fanspe
     {
       if (fanpolicy == 1)
       {
-        NV_GPU_COOLER_LEVELS CoolerLevels = { 0 };
+        NV_GPU_COOLER_LEVELS CoolerLevels;
+
+        memset (&CoolerLevels, 0, sizeof (NV_GPU_COOLER_LEVELS));
 
         CoolerLevels.Version = GPU_COOLER_LEVELS_VER | sizeof (NV_GPU_COOLER_LEVELS);
 
@@ -4386,9 +4388,12 @@ char *get_exec_path ()
   mib[2] = KERN_PROC_PATHNAME;
   mib[3] = -1;
 
-  size_t size = sizeof(exec_path);
+  char tmp[32] = { 0 };
+
+  size_t size = exec_path_len;
+  sysctl(mib, 4, exec_path, &size, NULL, 0);
 
-  const int len = sysctl(mib, 4, exec_path, &size, NULL, 0);
+  const int len = readlink (tmp, exec_path, exec_path_len - 1);
 
   #else
   #error Your Operating System is not supported or detected
@@ -4720,8 +4725,9 @@ int sort_by_hash_t_salt_hccap (const void *v1, const void *v2)
   const salt_t *s1 = h1->salt;
   const salt_t *s2 = h2->salt;
 
-  // 16 - 2 (since last 2 uints contain the digest)
-  uint n = 14;
+  // last 2: salt_buf[10] and salt_buf[11] contain the digest (skip them)
+
+  uint n = 9; // 9 * 4 = 36 bytes (max length of ESSID)
 
   while (n--)
   {
@@ -6172,9 +6178,10 @@ void ascii_digest (char *out_buf, uint salt_pos, uint digest_pos)
 
   uint len = 4096;
 
-  uint digest_buf[64] = { 0 };
+  u8 datax[256] = { 0 };
 
-  u64 *digest_buf64 = (u64 *) digest_buf;
+  u64 *digest_buf64 = (u64 *) datax;
+  u32 *digest_buf   = (u32 *) datax;
 
   char *digests_buf_ptr = (char *) data.digests_buf;