2
0
mirror of https://github.com/openvswitch/ovs synced 2025-10-17 14:28:02 +00:00

ofp-parse: Correctly update bucket lists if they are empty.

Previously, list_moved() only worked with non-empty lists, but this was a
caveat that was really easy to miss.  parse_ofp_group_mod_file() had a bug
because it didn't honor that restriction.  This commit fixes the problem,
by modifying the list_moved() interface to be harder to use incorrectly
and then updating the callers.

Reported-by: Simon Horman <simon.horman@netronome.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Thomas Graf <tgraf@noironetworks.com>
This commit is contained in:
Ben Pfaff
2015-02-13 14:31:21 -08:00
parent ee32150e7f
commit c7ecbf1e9c
2 changed files with 21 additions and 17 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2013 Nicira, Inc.
* Copyright (c) 2008, 2009, 2010, 2011, 2013, 2015 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,7 +33,7 @@ static inline void list_splice(struct ovs_list *before, struct ovs_list *first,
static inline void list_push_front(struct ovs_list *, struct ovs_list *);
static inline void list_push_back(struct ovs_list *, struct ovs_list *);
static inline void list_replace(struct ovs_list *, const struct ovs_list *);
static inline void list_moved(struct ovs_list *);
static inline void list_moved(struct ovs_list *, const struct ovs_list *orig);
static inline void list_move(struct ovs_list *dst, struct ovs_list *src);
/* List removal. */
@@ -150,15 +150,21 @@ list_replace(struct ovs_list *element, const struct ovs_list *position)
}
/* Adjusts pointers around 'list' to compensate for 'list' having been moved
* around in memory (e.g. as a consequence of realloc()).
* around in memory (e.g. as a consequence of realloc()), with original
* location 'orig'.
*
* This always works if 'list' is a member of a list, or if 'list' is the head
* of a non-empty list. It fails badly, however, if 'list' is the head of an
* empty list; just use list_init() in that case. */
* ('orig' likely points to freed memory, but this function does not
* dereference 'orig', it only compares it to 'list'. In a very pedantic
* language lawyer sense, this still yields undefined behavior, but it works
* with actual compilers.) */
static inline void
list_moved(struct ovs_list *list)
list_moved(struct ovs_list *list, const struct ovs_list *orig)
{
list->prev->next = list->next->prev = list;
if (list->next == orig) {
list_init(list);
} else {
list->prev->next = list->next->prev = list;
}
}
/* Initializes 'dst' with the contents of 'src', compensating for moving it
@@ -167,12 +173,8 @@ list_moved(struct ovs_list *list)
static inline void
list_move(struct ovs_list *dst, struct ovs_list *src)
{
if (!list_is_empty(src)) {
*dst = *src;
list_moved(dst);
} else {
list_init(dst);
}
*dst = *src;
list_moved(dst, src);
}
/* Removes 'elem' from its list and returns the element that followed it.

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
* Copyright (c) 2010, 2011, 2012, 2013, 2014, 2015 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -1413,12 +1413,14 @@ parse_ofp_group_mod_file(const char *file_name, uint16_t command,
char *error;
if (*n_gms >= allocated_gms) {
struct ofputil_group_mod *new_gms;
size_t i;
*gms = x2nrealloc(*gms, &allocated_gms, sizeof **gms);
new_gms = x2nrealloc(*gms, &allocated_gms, sizeof **gms);
for (i = 0; i < *n_gms; i++) {
list_moved(&(*gms)[i].buckets);
list_moved(&new_gms[i].buckets, &(*gms)[i].buckets);
}
*gms = new_gms;
}
error = parse_ofp_group_mod_str(&(*gms)[*n_gms], command, ds_cstr(&s),
&usable);