From 6accffd583c743c2dc8fad8675227ccc2084a3c6 Mon Sep 17 00:00:00 2001 From: Jens Remus Date: Tue, 5 Sep 2017 22:03:38 +0200 Subject: [PATCH] fdasd: fix possible integer overflow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The computation of blk in functions fdasd_check_volume() and fdasd_write_vtoc_labels() contained the possibility for an undetected unsigned integer overflow. Unconditionally subtracting one from the return value of function cchhb2blk() may cause an unsigned integer overflow, as cchhb2blk() may return zero if cc, hh, and b are all zero. Resolves Cppcheck style warning: [fdasd/fdasd.c:1260]: (style) Checking if unsigned variable 'blk' is less than zero. Cc: Stefan Haberland Cc: Jan Hoeppner Signed-off-by: Jens Remus Reviewed-by: Jan Höppner Signed-off-by: Jan Höppner --- fdasd/fdasd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fdasd/fdasd.c b/fdasd/fdasd.c index 085d2beb..ffc1e9dc 100644 --- a/fdasd/fdasd.c +++ b/fdasd/fdasd.c @@ -1,7 +1,7 @@ /* * fdasd - Create or modify partitions on ECKD DASDs * - * Copyright IBM Corp. 2001, 2017 + * Copyright IBM Corp. 2001, 2018 * * s390-tools is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. @@ -1257,7 +1257,7 @@ static void fdasd_write_vtoc_labels(fdasd_anchor_t *anc) printf("DSCBs: "); blk = (cchhb2blk(&anc->vlabel->vtoc, &geo) - 1) * anc->blksize; - if (blk <= 0) + if (cchhb2blk(&anc->vlabel->vtoc, &geo) == 0 || blk == 0) fdasd_error(anc, vlabel_corrupted, ""); maxblk = blk + anc->blksize * 9; /* f4+f5+f7+3*f8+3*f9 */ @@ -1994,7 +1994,7 @@ static int fdasd_check_volume(fdasd_anchor_t *anc) printf(" VOL1\n"); blk = (cchhb2blk(&vlabel->vtoc, &geo) - 1) * anc->blksize; - if (blk > 0) { + if (cchhb2blk(&vlabel->vtoc, &geo) > 0 && blk > 0) { rc = fdasd_valid_vtoc_pointer(anc, blk); if (anc->print_table && (rc < 0))