GNOME Bugzilla – Bug 764132
[review] escape arguments when exporting Openvpn configuration and cleanup [th/export-bgo764132]
Last modified: 2016-03-29 11:34:37 UTC
When writing a openvpn configuration file during export, we must properly handle special characters (escaping). Thereby, also refactor the code. Especially, don't have a pre-ample where we lookup all the values first and write them later. Just do it all in one place.
> properties: refactor export code to properly escape strings +static const char * +escape_arg (const char *value, char **buf) If the string contains a single quote, backslash and double quotes are escaped, but spaces are not. I think we have to either escape them or enclose the string in double quotes. + : (tmp_proto + ? (!strcmp (tmp_proto, "udp") nm_streq ? > properties: refactor do_export() to first write the file to a GString buffer > properties: use g_file_sets_contents() to write file in do_export() Maybe squash these two? Otherwise the comment in the first commit about error checking is misleading (error checking is added later). + args_write_line (f, + "dev", + device ?: + (device_type ?: + (nm_streq0 (nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_TAP_DEV), "yes") + ? "tun" : "tap"))); should be: ? "tap" : "tun"))); The rest LGTM.
(In reply to Beniamino Galvani from comment #1) > > properties: refactor export code to properly escape strings > > +static const char * > +escape_arg (const char *value, char **buf) > > If the string contains a single quote, backslash and double quotes are > escaped, but spaces are not. I think we have to either escape them or > enclose the string in double quotes. Good catch. Previous version was badly messed up. How about now? > + : (tmp_proto > + ? (!strcmp (tmp_proto, "udp") > > nm_streq ? fixup! > > properties: refactor do_export() to first write the file to a GString buffer > > properties: use g_file_sets_contents() to write file in do_export() > > Maybe squash these two? Otherwise the comment in the first commit > about error checking is misleading (error checking is added later). I reworded the commit message of the first commit. Ok? > + args_write_line (f, > + "dev", > + device ?: > + (device_type ?: > + (nm_streq0 (nm_setting_vpn_get_data_item > (s_vpn, NM_OPENVPN_KEY_TAP_DEV), "yes") > + ? "tun" : "tap"))); > > should be: ? "tap" : "tun"))); fixup! Repushed
merged to master: https://git.gnome.org/browse/network-manager-openvpn/commit/?id=4f9ab03596b5559ab6f428ecdec864945c202570