[ovs-dev] [Simple DB Stats 06/11] ovsdb-idlc: Fix sizeof calculation in generated code.
Justin Pettit
jpettit at nicira.com
Tue Jun 22 15:35:16 PDT 2010
Nice catch!
--Justin
On Jun 10, 2010, at 5:14 PM, Ben Pfaff wrote:
> Generated <prefix>_<struct>_parse_<column> functions did not allocate
> enough memory for the "value" array, because code that should have said,
> e.g.:
> row->value_options = xmalloc(datum->n * sizeof *row->value_options);
> actually said:
> row->value_options = xmalloc(datum->n * sizeof row->value_options);
>
> This fixes the problem. I also checked that the same problem didn't occur
> elsewhere in the generated code.
>
> (This would be a fairly serious bug fix, because without it reads and
> writes beyond the end of allocated memory would be almost inevitable,
> except that every existing map has string values, and sizeof(char*)
> == sizeof(char**) on any sane system.)
> ---
> ovsdb/ovsdb-idlc.in | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/ovsdb/ovsdb-idlc.in b/ovsdb/ovsdb-idlc.in
> index c89048e..d545d64 100755
> --- a/ovsdb/ovsdb-idlc.in
> +++ b/ovsdb/ovsdb-idlc.in
> @@ -311,7 +311,7 @@ static void
> print "%sif (!row->n_%s) {" % (indent, columnName)
> print "%s %s = xmalloc(%s * sizeof *%s);" % (indent, keyVar, nMax, keyVar)
> if valueVar:
> - print "%s %s = xmalloc(%s * sizeof %s);" % (indent, valueVar, nMax, valueVar)
> + print "%s %s = xmalloc(%s * sizeof *%s);" % (indent, valueVar, nMax, valueVar)
> print "%s}" % indent
> print "%s%s[row->n_%s] = %s;" % (indent, keyVar, columnName, keySrc)
> if valueVar:
> --
> 1.7.1
>
>
> _______________________________________________
> dev mailing list
> dev at openvswitch.org
> http://openvswitch.org/mailman/listinfo/dev_openvswitch.org
More information about the dev
mailing list