Fix for -I parameter workaround, use chdir () before modifying cpath_real
[hashcat.git] / src / hashcat.c
index 027dd02..40adbc6 100644 (file)
@@ -6147,6 +6147,22 @@ int main (int argc, char **argv)
 
   umask (077);
 
+  /**
+   * There's some buggy OpenCL runtime that do not support -I.
+   * A workaround is to chdir() to the OpenCL folder,
+   * then compile the kernels,
+   * then chdir() back to where we came from so we need to save it first
+   */
+
+  char cwd[1024];
+
+  if (getcwd (cwd, sizeof (cwd) - 1) == NULL)
+  {
+    log_error ("ERROR: getcwd(): %s", strerror (errno));
+
+    return -1;
+  }
+
   /**
    * Real init
    */
@@ -14260,6 +14276,7 @@ int main (int argc, char **argv)
       }
 
       if (platform_skipped == 1) continue;
+      if (platform_skipped == 2) continue;
 
       for (uint platform_devices_id = 0; platform_devices_id < platform_devices_cnt; platform_devices_id++)
       {
@@ -16090,12 +16107,6 @@ int main (int argc, char **argv)
         return -1;
       }
 
-      naive_replace (cpath_real, '\\', '/');
-
-      // not escaping here, windows has quotes
-
-      snprintf (build_opts, sizeof (build_opts) - 1, "-I \"%s\"", cpath_real);
-
       #else
 
       snprintf (cpath, sizeof (cpath) - 1, "%s/OpenCL/", shared_dir);
@@ -16109,6 +16120,25 @@ int main (int argc, char **argv)
         return -1;
       }
 
+      #endif
+
+      if (chdir (cpath_real) == -1)
+      {
+        log_error ("ERROR: %s: %s", cpath_real, strerror (errno));
+
+        return -1;
+      }
+
+      #if _WIN
+
+      naive_replace (cpath_real, '\\', '/');
+
+      // not escaping here, windows has quotes
+
+      snprintf (build_opts, sizeof (build_opts) - 1, "-I \"%s\"", cpath_real);
+
+      #else
+
       naive_escape (cpath_real, PATH_MAX,  ' ', '\\');
 
       snprintf (build_opts, sizeof (build_opts) - 1, "-I %s", cpath_real);
@@ -16142,15 +16172,11 @@ int main (int argc, char **argv)
 
       for (int i = 0; i < files_cnt; i++)
       {
-        char path[1024] = { 0 };
-
-        snprintf (path, sizeof (path) - 1, "%s/%s", cpath_real, files_names[i]);
-
-        FILE *fd = fopen (path, "r");
+        FILE *fd = fopen (files_names[i], "r");
 
         if (fd == NULL)
         {
-          log_error ("ERROR: %s: fopen(): %s", path, strerror (errno));
+          log_error ("ERROR: %s: fopen(): %s", files_names[i], strerror (errno));
 
           return -1;
         }
@@ -16161,7 +16187,7 @@ int main (int argc, char **argv)
 
         if (n != 1)
         {
-          log_error ("ERROR: %s: fread(): %s", path, strerror (errno));
+          log_error ("ERROR: %s: fread(): %s", files_names[i], strerror (errno));
 
           return -1;
         }
@@ -16718,6 +16744,15 @@ int main (int argc, char **argv)
         local_free (kernel_sources);
       }
 
+      // return back to the folder we came from initially (workaround)
+
+      if (chdir (cwd) == -1)
+      {
+        log_error ("ERROR: %s: %s", cwd, strerror (errno));
+
+        return -1;
+      }
+
       // some algorithm collide too fast, make that impossible
 
       if (benchmark == 1)