1 --- origin/main.c 2016-12-12 12:53:38.344285376 +0100
2 +++ main.c 2016-12-12 13:01:41.134548824 +0100
6 #ifdef USE_UNIX_REDIRECTION
7 -#define DEVNULL ">/dev/null 2>&1"
8 +#define DEVNULL "/dev/null"
10 -#define DEVNULL ">NUL 2>&1"
11 +#define DEVNULL "NUL"
21 check_unzip (const char *pw)
30 + exit (EXIT_FAILURE);
35 + // Redirect STDERR/STDOUT to /dev/null
36 + int oldfd_stderr, oldfd_stdout;
37 + oldfd_stdout = dup (fileno (stdout));
38 + if (oldfd_stdout == -1)
40 + perror ("dup for stdout");
43 + oldfd_stderr = dup (fileno (stderr));
44 + if (oldfd_stderr == -1)
46 + perror ("dup for stderr");
49 + if (freopen (DEVNULL, "w", stdout) == NULL)
51 + perror ("freopen " DEVNULL " for stdout");
54 + if (freopen (DEVNULL, "w", stderr) == NULL)
56 + perror ("freopen " DEVNULL " for stderr");
59 + execlp ("unzip", "unzip", "-qqtP", pw, file_path[0], NULL);
61 + // When execlp failed.
62 + // Restores the stderr/stdout redirection to print an error.
63 + int errno_saved = errno;
64 + dup2 (oldfd_stderr, fileno (stderr));
65 + dup2 (oldfd_stdout, fileno (stdout));
66 + close (oldfd_stderr);
67 + close (oldfd_stdout);
68 + errno = errno_saved;
69 + perror ("execlp for unzip");
70 + _exit (127); // Returns 127 on error as system(3) does
73 - sprintf (buff, "unzip -qqtP \"%s\" %s " DEVNULL, pw, file_path[0]);
74 - status = system (buff);
79 - if (status == EXIT_SUCCESS)
80 + if (waitpid (cpid, &status, 0) == -1)
82 - printf("\n\nPASSWORD FOUND!!!!: pw == %s\n", pw);
84 + exit (EXIT_FAILURE);
87 + // The child process does not terminated normally, OR returns the exit status 127.
88 + if (!WIFEXITED (status)
89 + || (WIFEXITED (status) && (WEXITSTATUS (status) == 127)))
91 + fprintf (stderr, "Executing unzip failed.\n");
92 + exit (EXIT_FAILURE);
94 +// unzip exited normally with the exit status 0 then...
95 + if (WIFEXITED (status) && (WEXITSTATUS (status) == EXIT_SUCCESS))
97 + printf ("\n\nPASSWORD FOUND!!!!: pw == %s\n", pw);
105 /* misc. callbacks. */