Skip to content

Commit

Permalink
Fix UTF-8 handling of config file name
Browse files Browse the repository at this point in the history
If we're going to convert the filename *from* UTF-8 when opening it, then
we really ought to be convert it *to* UTF-8 first. This would have shown
up if invoking openconnect in a non-UTF-8 locale, with a non-ASCII
filename.

On POSIX systems this whole thing is a no-op, since converting from any
arbitrary 8-bit charset to UTF-8 and back again effectively does nothing.

However, on Windows the convert_arg_to_utf8() function doesn't just work
on the input string; it looks aside with GetCommandLineW() to find the
*original* text on the command line, and uses that instead. So we really
do have to do the double "conversion" — even when it's simply converting to
UTF-8, *immediately* converting back again (in fopen_utf8()), and *never*
using it again.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
  • Loading branch information
David Woodhouse authored and David Woodhouse committed Aug 4, 2014
1 parent 4fbec3c commit b8e7274
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion main.c
Expand Up @@ -898,6 +898,7 @@ int main(int argc, char **argv)
int use_dtls = 1;
FILE *fp = NULL;
char *config_arg;
char *config_filename;
char *token_str = NULL;
oc_token_mode_t token_mode = OC_TOKEN_MODE_NONE;
int reconnect_timeout = 300;
Expand Down Expand Up @@ -1012,7 +1013,10 @@ int main(int argc, char **argv)
fprintf(stderr, _("Cannot use 'config' option inside config file\n"));
exit(1);
}
config_file = openconnect_fopen_utf8(vpninfo, config_arg, "r");
config_filename = keep_config_arg(); /* Convert to UTF-8 */
config_file = openconnect_fopen_utf8(vpninfo, config_filename, "r");
if (config_filename != config_arg)
free(config_filename);
if (!config_file) {
fprintf(stderr, _("Cannot open config file '%s': %s\n"),
config_arg, strerror(errno));
Expand Down

0 comments on commit b8e7274

Please sign in to comment.