The UnRAR library requires the character-classification locale to be set
to the empty string "" so it will be set according to the environment
variables, as seeen in the rar.cpp example application `main()`.
Without this, extracting RAR archives containing unicode filenames on
non-Windows, non-macOS operating systems may fail.
| ... | ... |
@@ -45,6 +45,7 @@ |
| 45 | 45 |
#endif |
| 46 | 46 |
#include <signal.h> |
| 47 | 47 |
#include <errno.h> |
| 48 |
+#include <locale.h> |
|
| 48 | 49 |
|
| 49 | 50 |
#if defined(USE_SYSLOG) && !defined(C_AIX) |
| 50 | 51 |
#include <syslog.h> |
| ... | ... |
@@ -155,6 +156,9 @@ int main(int argc, char **argv) |
| 155 | 155 |
sa.sa_handler = SIG_IGN; |
| 156 | 156 |
sigaction(SIGHUP, &sa, NULL); |
| 157 | 157 |
sigaction(SIGUSR2, &sa, NULL); |
| 158 |
+ if(!setlocale(LC_CTYPE, "")) {
|
|
| 159 |
+ mprintf("^Failed to set locale\n");
|
|
| 160 |
+ } |
|
| 158 | 161 |
#endif |
| 159 | 162 |
|
| 160 | 163 |
if ((opts = optparse(NULL, argc, argv, 1, OPT_CLAMD, 0, NULL)) == NULL) {
|
| ... | ... |
@@ -27,6 +27,7 @@ |
| 27 | 27 |
#include <stdlib.h> |
| 28 | 28 |
#include <string.h> |
| 29 | 29 |
#include <signal.h> |
| 30 |
+#include <locale.h> |
|
| 30 | 31 |
|
| 31 | 32 |
#ifdef HAVE_UNISTD_H |
| 32 | 33 |
#include <unistd.h> |
| ... | ... |
@@ -76,11 +77,16 @@ int main(int argc, char **argv) |
| 76 | 76 |
if (check_flevel()) |
| 77 | 77 |
exit(2); |
| 78 | 78 |
|
| 79 |
-#if !defined(_WIN32) && !defined(C_BEOS) |
|
| 79 |
+#if !defined(_WIN32) |
|
| 80 |
+ if(!setlocale(LC_CTYPE, "")) {
|
|
| 81 |
+ mprintf("^Failed to set locale\n");
|
|
| 82 |
+ } |
|
| 83 |
+#if !defined(C_BEOS) |
|
| 80 | 84 |
sigemptyset(&sigset); |
| 81 | 85 |
sigaddset(&sigset, SIGXFSZ); |
| 82 | 86 |
sigprocmask(SIG_SETMASK, &sigset, NULL); |
| 83 |
-#endif |
|
| 87 |
+#endif /* !C_BEOS */ |
|
| 88 |
+#endif /* !_WIN32 */ |
|
| 84 | 89 |
|
| 85 | 90 |
cl_initialize_crypto(); |
| 86 | 91 |
|