[Spice-devel] [usbredir PATCH 6/6] usbredirfilter: fix filter parsing for windows (mingw)

Christophe Fergeau cfergeau at redhat.com
Thu May 3 09:09:23 PDT 2012


On Thu, May 03, 2012 at 06:04:39PM +0300, Uri Lublin wrote:
> From: Arnon Gilboa <agilboa at redhat.com>
> 
> no strtok_r (reentrent) available, so use strtok instead.

Wouldn't it be safer to use strtok_s? Any application using threads and
strtok and libusbredirparser could get issues with this change no?

> 
> Modified-by: Uri Lublin <uril at redhat.com>
> ---
>  usbredirparser/usbredirfilter.c |   16 +++++++++++-----
>  1 files changed, 11 insertions(+), 5 deletions(-)
> 
> diff --git a/usbredirparser/usbredirfilter.c b/usbredirparser/usbredirfilter.c
> index b74c921..a1213cc 100644
> --- a/usbredirparser/usbredirfilter.c
> +++ b/usbredirparser/usbredirfilter.c
> @@ -29,7 +29,7 @@ int usbredirfilter_string_to_rules(
>      const char *filter_str, const char *token_sep, const char *rule_sep,
>      struct usbredirfilter_rule **rules_ret, int *rules_count_ret)
>  {
> -    char *rule, *rule_saveptr, *token, *token_saveptr, *ep;
> +    char *rule, *token, *ep, *buf_end, *rule_end;
>      struct usbredirfilter_rule *rules = NULL;
>      int i, rules_count, *values, ret = 0;
>      char *buf = NULL;
> @@ -63,17 +63,19 @@ int usbredirfilter_string_to_rules(
>      }
> 
>      /* And actually parse the string */
> +    buf_end = buf + strlen(buf);
>      rules_count = 0;
> -    rule = strtok_r(buf, rule_sep, &rule_saveptr);
> +    rule = strtok(buf, rule_sep);
>      while (rule) {
> +        rule_end = rule + strlen(rule);
>          /* We treat the filter rule as an array of ints for easier parsing */
>          values = (int *)&rules[rules_count];
> -        token = strtok_r(rule, token_sep, &token_saveptr);
> +        token = strtok(rule, token_sep);
>          for (i = 0; i < 5 && token; i++) {
>              values[i] = strtol(token, &ep, 0);
>              if (*ep)
>                  break;
> -            token = strtok_r(NULL, token_sep, &token_saveptr);
> +            token = strtok(NULL, token_sep);
>          }
>          if (i != 5 || token != NULL ||
>                  usbredirfilter_verify(&rules[rules_count], 1)) {
> @@ -81,7 +83,11 @@ int usbredirfilter_string_to_rules(
>              goto leave;
>          }
>          rules_count++;
> -        rule = strtok_r(NULL, rule_sep, &rule_saveptr);
> +        if (rule_end < buf_end) {
> +            rule = strtok(rule_end + 1, rule_sep);
> +        } else {
> +            rule = NULL;
> +        }

rule = strtok(NULL, rule_sep); didn't work there? I'm bad with
strtok/strtok_r, but by reading the manpage, it doesn't seem things should
be handled differently there.

Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/spice-devel/attachments/20120503/fb648f10/attachment-0001.pgp>


More information about the Spice-devel mailing list