X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=lib%2Flearn.c;h=9d97cb35cdfd28747ec066f5600d7f8de6df9ab3;hb=acd051f1761569205827dc9b037e15568a8d59f8;hp=19a0e009044d8284dc821312f0edfa8eb0e5098e;hpb=28da1f8f725fc2a797174df18a7b3e31ef49ede0;p=openvswitch diff --git a/lib/learn.c b/lib/learn.c index 19a0e009..9d97cb35 100644 --- a/lib/learn.c +++ b/lib/learn.c @@ -621,6 +621,17 @@ learn_format(const struct nx_action_learn *learn, struct ds *s) union mf_value value; uint8_t *bytes = (uint8_t *) &value; + if (src_value_bytes > dst_field->n_bytes) { + /* The destination field is an odd number of bytes, which + * got rounded up to a multiple of 2 to be put into the + * learning action. Skip over the leading byte, which + * should be zero anyway. Otherwise the memcpy() below + * will overrun the start of 'value'. */ + int diff = src_value_bytes - dst_field->n_bytes; + src_value += diff; + src_value_bytes -= diff; + } + memset(&value, 0, sizeof value); memcpy(&bytes[dst_field->n_bytes - src_value_bytes], src_value, src_value_bytes);