On 22/01/13 12:36, Heiko Hund wrote:
> Currently openvpn exits when reading configuration from a file
> that has an UTF-8 byte order mark (EF BB BF) at its start.
> 
> While it is useless to put a BOM into UTF-8 encoded files, the
> Unicode standard [1] permits it (on page 36):
> 
>   "Use of a BOM is neither required nor recommended for UTF-8,
>   but may be encountered in contexts where UTF-8 data is converted
>   from other encoding forms that use a BOM or where the BOM is
>   used as a UTF-8 signature."
> 
> Notepad.exe, the default text editor on Windows, always puts the BOM
> into UTF-8 encoded files when saving them. Others may do as well.
> 
> Just ignoring the UTF-8 BOM will make config files with UTF-8 BOM
> readable.
> 
> [1] http://www.unicode.org/versions/Unicode5.0.0/ch02.pdf
> 
> Signed-off-by: Heiko Hund <heiko.h...@sophos.com>
> 
> ---
>  src/openvpn/options.c |    3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/src/openvpn/options.c b/src/openvpn/options.c
> index 99f70ad..46f6f26 100644
> --- a/src/openvpn/options.c
> +++ b/src/openvpn/options.c
> @@ -3773,6 +3773,9 @@ read_config_file (struct options *options,
>           {
>             CLEAR (p);
>             ++line_num;
> +              /* Ignore UTF-8 BOM at start of stream */
> +              if (line_num == 1 && strncmp (line, "\xEF\xBB\xBF", 3) == 0)
> +                memmove (line, line + 3, strlen (line) - 2);
>             if (parse_line (line, p, SIZE (p), file, line_num, msglevel, 
> &options->gc))

Wouldn't this approach solve it in an easier way?

       int offset = 0;
       if (line_num == 1 && strncmp (line, "\xEF\xBB\xBF", 3) == 0)
          offset = 3

       if (parse_line (line+offset, p, SIZE (p), file, line_num ....

Should be safer as you don't need care about proper NULL termination of
the buffer.


-- 
kind regards,

David Sommerseth

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to