From: Robert Kessl Date: Fri, 25 Jul 2014 15:28:59 +0000 (+0200) Subject: tableprinter: added overflow detection X-Git-Tag: v6.1~3^2~38 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=54dde0cff42c7f1363cf28d16ab6f54232b672e8;p=libucw.git tableprinter: added overflow detection --- diff --git a/ucw/table-types.c b/ucw/table-types.c index 235ceac3..b483ec55 100644 --- a/ucw/table-types.c +++ b/ucw/table-types.c @@ -126,6 +126,12 @@ static const char *xt_size_parse(const char *str, void *dest, struct mempool *po } // FIXME: Detect overflow? + u64 num = xt_size_units[unit_idx].num; + if((parsed && UINT64_MAX / parsed < num) || + (num && UINT64_MAX / num < parsed)) { + return mp_printf(pool, "Size too large: '%s'.", str); + } + *(u64*) dest = parsed * xt_size_units[unit_idx].num; return NULL; }