lkml.org 
[lkml]   [2015]   [Oct]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH v3 2/4] lib/string_helpers.c: protect string_get_size() against blk_size=0
    Date
    Division by zero happens if blk_size=0 is supplied to string_get_size().
    Add WARN_ON() and set size to 0 to report '0 B'.

    Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
    ---
    lib/string_helpers.c | 5 +++++
    1 file changed, 5 insertions(+)

    diff --git a/lib/string_helpers.c b/lib/string_helpers.c
    index f6c27dc..ff3575b 100644
    --- a/lib/string_helpers.c
    +++ b/lib/string_helpers.c
    @@ -50,6 +50,11 @@ void string_get_size(u64 size, u32 blk_size, const enum string_size_units units,

    tmp[0] = '\0';
    i = 0;
    +
    + /* Calling string_get_size() with blk_size=0 is wrong! */
    + if (WARN_ON(!blk_size))
    + size = 0;
    +
    if (!size)
    goto out;

    --
    2.4.3


    \
     
     \ /
      Last update: 2015-10-29 17:41    [W:3.765 / U:1.072 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site