Acked-by: Jarno Rajahalme <ja...@ovn.org>

> On Feb 10, 2016, at 3:56 PM, Ben Pfaff <b...@ovn.org> wrote:
> 
> This makes it accept the same syntax as parse_NOTE(), so that that function
> can be simplified.  In an upcoming commit a second action will also be
> able to take advantage of the same feature.
> 
> Signed-off-by: Ben Pfaff <b...@ovn.org>
> ---
> v3: New patch.
> v3->v4: Fix use-after-free error.
> 
> lib/ofp-actions.c | 34 +++++++++-------------------------
> lib/ofpbuf.c      | 12 ++++++------
> 2 files changed, 15 insertions(+), 31 deletions(-)
> 
> diff --git a/lib/ofp-actions.c b/lib/ofp-actions.c
> index 9b75526..24f18d9 100644
> --- a/lib/ofp-actions.c
> +++ b/lib/ofp-actions.c
> @@ -4401,31 +4401,15 @@ static char * OVS_WARN_UNUSED_RESULT
> parse_NOTE(const char *arg, struct ofpbuf *ofpacts,
>            enum ofputil_protocol *usable_protocols OVS_UNUSED)
> {
> -    struct ofpact_note *note;
> -
> -    note = ofpact_put_NOTE(ofpacts);
> -    while (*arg != '\0') {
> -        uint8_t byte;
> -        bool ok;
> -
> -        if (*arg == '.') {
> -            arg++;
> -        }
> -        if (*arg == '\0') {
> -            break;
> -        }
> -
> -        byte = hexits_value(arg, 2, &ok);
> -        if (!ok) {
> -            return xstrdup("bad hex digit in `note' argument");
> -        }
> -        ofpbuf_put(ofpacts, &byte, 1);
> -
> -        note = ofpacts->header;
> -        note->length++;
> -
> -        arg += 2;
> -    }
> +    size_t start_ofs = ofpacts->size;
> +    ofpact_put_NOTE(ofpacts);
> +    arg = ofpbuf_put_hex(ofpacts, arg, NULL);
> +    if (arg[0]) {
> +        return xstrdup("bad hex digit in `note' argument");
> +    }
> +    struct ofpact_note *note = ofpbuf_at_assert(ofpacts, start_ofs,
> +                                                sizeof *note);
> +    note->length = ofpacts->size - (start_ofs + sizeof *note);
>     ofpact_finish(ofpacts, &note->ofpact);
>     return NULL;
> }
> diff --git a/lib/ofpbuf.c b/lib/ofpbuf.c
> index c190f8b..a3c4da4 100644
> --- a/lib/ofpbuf.c
> +++ b/lib/ofpbuf.c
> @@ -1,5 +1,5 @@
> /*
> - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
> + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2016 Nicira, Inc.
>  *
>  * Licensed under the Apache License, Version 2.0 (the "License");
>  * you may not use this file except in compliance with the License.
> @@ -389,10 +389,10 @@ ofpbuf_put(struct ofpbuf *b, const void *p, size_t size)
>     return dst;
> }
> 
> -/* Parses as many pairs of hex digits as possible (possibly separated by
> - * spaces) from the beginning of 's', appending bytes for their values to 
> 'b'.
> - * Returns the first character of 's' that is not the first of a pair of hex
> - * digits.  If 'n' is nonnull, stores the number of bytes added to 'b' in
> +/* Parses as many pairs of hex digits as possible (possibly separated by 
> spaces
> + * or periods) from the beginning of 's', appending bytes for their values to
> + * 'b'.  Returns the first character of 's' that is not the first of a pair 
> of
> + * hex digits.  If 'n' is nonnull, stores the number of bytes added to 'b' in
>  * '*n'. */
> char *
> ofpbuf_put_hex(struct ofpbuf *b, const char *s, size_t *n)
> @@ -402,7 +402,7 @@ ofpbuf_put_hex(struct ofpbuf *b, const char *s, size_t *n)
>         uint8_t byte;
>         bool ok;
> 
> -        s += strspn(s, " \t\r\n");
> +        s += strspn(s, " .\t\r\n");
>         byte = hexits_value(s, 2, &ok);
>         if (!ok) {
>             if (n) {
> -- 
> 2.1.3
> 
> _______________________________________________
> dev mailing list
> dev@openvswitch.org
> http://openvswitch.org/mailman/listinfo/dev

_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to