From patchwork Wed Apr 17 16:19:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Albershteyn X-Patchwork-Id: 13633583 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 44CB414901E for ; Wed, 17 Apr 2024 16:19:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713370781; cv=none; b=PFjjrgk0cGzpNCZSUj4PQUAHmotLUSCK+pw+gi/G8QhmCS0FaYiFwvq1v3C1xX+TQSFrqNawBsSLkSkBpn3RragGbab2npO82OyqDout1Ph3XvLQU/iU57xA15lYgy44jqyLfOBwe7bx/ar7dBBL2PwhuD6W24UVpFSfNKO8rw0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713370781; c=relaxed/simple; bh=kfopneWVUzAWtOEy8Qg0l7TIUCGXxxCSaPD9GnIirMw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TJetjEARiS/LIbyLk/ufG70q7FhKI5rqVsnYxPMJlh6qJiwGDgQYdKCpq6guJtG9jHuNz1X3aprAufctiKBhi/00rIkR1rZ2xVjqZzhdw3N4zRdEbw3F66eAVLdFV21i24pKGtSONPGA2W2Kvbi1iZfmbK+yddeSj23dCzWw9f8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=E8Gjx63j; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="E8Gjx63j" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1713370779; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IiaO8seLkPKK5bXXWNYfUJC8WqVyivK7Zsl5rhBzW04=; b=E8Gjx63j8NAyRF8L0EtVahLSFxQuNPKKg6lJj+eeNeIfRCX82XhNvThZqxEki1ISVhJd4J RS+DJcbxoExopx7ETv2DQ1R83FEJv5uWo1homMkFPAHAmaNuXs0ZWe5EUo3bym8ZtOZ925 nCcBeRKZ+2x5XiDG/m6dWL7fDFJZzCs= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-428-HbdH0yKuNNaeqAaAwdkDRQ-1; Wed, 17 Apr 2024 12:19:37 -0400 X-MC-Unique: HbdH0yKuNNaeqAaAwdkDRQ-1 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-a46852c2239so441481366b.1 for ; Wed, 17 Apr 2024 09:19:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713370776; x=1713975576; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IiaO8seLkPKK5bXXWNYfUJC8WqVyivK7Zsl5rhBzW04=; b=frP9wXALAONdfOEy1s5x29SmRwMZbbixoArNSKXdV7UZkQE16ZDn3XiAdvPk1zeWky nDTmALdg+H3MbmOBlGmMvOKQqu+Nt4Vn44HI/2pC9fJVnOe8KDw0lYrClTqQnW/k7u/1 IhO3Jj7u0f5KOQ6GSBD+4bLJCYIZmYaLCSti8diG/hZDMApjYcNdbNrMBQAHPq0bljuv +SSNu6wxxlQ+iHqccB8MjWZvUB/iVNd6W/2f1heuoS+4x/UlJ3wHZEOeKZZJ1UnSReF9 6L9XeF0pSEXWoCABZoHqb0GWFkvO1E49qln8sTbPOkTKQLfobomxIcR1KvM6p2TBwaqK 9rZg== X-Forwarded-Encrypted: i=1; AJvYcCXmuPyJvhYI8rktsjAsbH5Fust7pi6h054lg7jXs8SovvfK3FxxapPBss9LlGdqeLQdmS8OqabVSG4hMRIgQTLvuSHEAwV+pt+l X-Gm-Message-State: AOJu0YyDEV5AgNRiDRIfWgbOcpugluNA5U/0H6FfMPiP6BhXmMvT62zf piOwBcJUxb5vncQ+eELFV1oiMV/+xOt8iRJHWZG7ic8pZtDpFfBRDg9K2wPyqf2WaK4Xak3Lz71 qW/ujR2lKPZloYskasIqOt67/3OhCaM0MMkoTqckRE3hvcdYq9Hg103Yd X-Received: by 2002:a17:907:bb86:b0:a52:6fcb:100f with SMTP id xo6-20020a170907bb8600b00a526fcb100fmr97ejc.12.1713370776323; Wed, 17 Apr 2024 09:19:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG7nxB59EJrFRzM0IQoQvh6HFdGzXDNDKriMErtaKZKSyl8060UGK3LyDU7KXv6mamsXuMW4Q== X-Received: by 2002:a17:907:bb86:b0:a52:6fcb:100f with SMTP id xo6-20020a170907bb8600b00a526fcb100fmr67ejc.12.1713370775582; Wed, 17 Apr 2024 09:19:35 -0700 (PDT) Received: from thinky.redhat.com ([109.183.6.197]) by smtp.gmail.com with ESMTPSA id q23-20020a170906a09700b00a519ec0a965sm8243334ejy.49.2024.04.17.09.19.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 09:19:34 -0700 (PDT) From: Andrey Albershteyn To: cem@kernel.org, linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@infradead.org, Andrey Albershteyn , Christoph Hellwig Subject: [PATCH v3 1/3] xfs_fsr: replace atoi() with strtol() Date: Wed, 17 Apr 2024 18:19:29 +0200 Message-ID: <20240417161931.964526-2-aalbersh@redhat.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240417161931.964526-1-aalbersh@redhat.com> References: <20240417161931.964526-1-aalbersh@redhat.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Replace atoi() which silently fails with strtol() and report the error. Signed-off-by: Andrey Albershteyn Reviewed-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fsr/xfs_fsr.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/fsr/xfs_fsr.c b/fsr/xfs_fsr.c index 02d61ef9399a..fdd37756030a 100644 --- a/fsr/xfs_fsr.c +++ b/fsr/xfs_fsr.c @@ -164,7 +164,13 @@ main(int argc, char **argv) usage(1); break; case 't': - howlong = atoi(optarg); + errno = 0; + howlong = strtol(optarg, NULL, 10); + if (errno) { + fprintf(stderr, _("%s: invalid runtime: %s\n"), + optarg, strerror(errno)); + exit(1); + } if (howlong > INT_MAX) { fprintf(stderr, _("%s: the maximum runtime is %d seconds.\n"), @@ -179,10 +185,24 @@ main(int argc, char **argv) mtab = optarg; break; case 'b': - argv_blksz_dio = atoi(optarg); + errno = 0; + argv_blksz_dio = strtol(optarg, NULL, 10); + if (errno) { + fprintf(stderr, + _("%s: invalid block size: %s\n"), + optarg, strerror(errno)); + exit(1); + } break; case 'p': - npasses = atoi(optarg); + errno = 0; + npasses = strtol(optarg, NULL, 10); + if (errno) { + fprintf(stderr, + _("%s: invalid number of passes: %s\n"), + optarg, strerror(errno)); + exit(1); + } break; case 'C': /* Testing opt: coerses frag count in result */ From patchwork Wed Apr 17 16:19:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Albershteyn X-Patchwork-Id: 13633584 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA6C914C593 for ; Wed, 17 Apr 2024 16:19:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713370783; cv=none; b=ldr7bg5QFQ1vvRygTmVrx4THBLwBw9rVYLceEkeE2qUA0kVnUClctBaZYIBOtJcDxxduWzkm7JLkIwzC0b/ZhwCo1+d+aGwbpvjz6Cy3z5/BcN+uBY124Vsy/BYpFImJimfLnHGAfKbttEXr53buNQNrkJdktyFYIN9c1h9aYsg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713370783; c=relaxed/simple; bh=9pfcxXvEU84XGfXaK4kwguLfHinxiloT0phRNBgdVds=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p0GU6ALqUHv4oC85PYJGRq8Bv/WpVOexFvgQgmW7UwxAw3pKaMCbBLiCWMthitJXNd1p3NCW15nVnWYp2jzSPmdC3uFkp3NrZBrVipKxzEIHMC4pz14MsXvCJ4tafjcJKwgdKot+TLs1iEawb1M0r5N8YrkOb9pDbYhvTdfgHAI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=crHKWFOw; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="crHKWFOw" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1713370780; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UE0+TY5xZUqmmHDZUeCm/+SX8krdCbBz9YQdSx7A4ck=; b=crHKWFOwZRe1vkag+a/pb+LcWLtAQ1HyeIgl3Qa8oZP58D6saw+wEzQu8RK6gs2gcKMsBs qUjRtmtLCmSYxRla1+Q1NzzrMBIm5TY++iWTCekVPGU/S/lVun03v6aoH6b5Wh5uAWG4uQ xHnX4+YlXbxEOngQUSFjVcszTQvEfeE= Received: from mail-lj1-f200.google.com (mail-lj1-f200.google.com [209.85.208.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-589-3NvFP4T1NG6KpMTAkf9brQ-1; Wed, 17 Apr 2024 12:19:38 -0400 X-MC-Unique: 3NvFP4T1NG6KpMTAkf9brQ-1 Received: by mail-lj1-f200.google.com with SMTP id 38308e7fff4ca-2db6fbc1dedso1098261fa.3 for ; Wed, 17 Apr 2024 09:19:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713370777; x=1713975577; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UE0+TY5xZUqmmHDZUeCm/+SX8krdCbBz9YQdSx7A4ck=; b=clBon7j0jRZ8yo181hF8dz13VFfXTEtYAWBPdS6r7l6G2fR5iNrZ+3++lQp/4Y8UGU IlT7A7zyLgINQExfNNDaz4qNvB6gmxTes3fBGavPvJflRLR3/3lovdPlkiH+OQUwOrZ6 RbD1UqpBSOhejZxHlFU7vwvau9a9k2dYZoNKK+yWvKySF4FqL+XaZ74GwRf3KjRM41dM D5KXkpsi8U64uy+EDGEoe+AP6bDiPfYTt2n44xVqTP2bw/5+a8zeWBktfzqlHFnofZ8u vsTgQAemAbMNavy4pEaFz6lQ0OJ/lxt8PnO+AAYQ6gBisIfAqu+8Jj4VRJqZgTK/2VKW Aa4w== X-Forwarded-Encrypted: i=1; AJvYcCVRNqasUwTwMwevFzROQXii/AYMkC0684UBPkk8t9kwXgfS6PXn6WgyL1bHhApFf9tPeATF44FITCsMEICPa7RWFMu2No0F4COc X-Gm-Message-State: AOJu0Yyw503xOZnfd9MRm9p1HHmikoYfDmRdn84QEfUYvOcfGwTV/hkZ y0Gxx4xbhNzt20y7oUfMNtq28Z6Q0SHu4Kyql+u2oVzF7lTpnhNAVFmgXF3gpLL0vaeLu+V9Xan tTzw65EPVT/PKKPx0N9R4/2cQV0dsVyJTfkt9dSdcQ4r6uQeIQ9akzj9d X-Received: by 2002:a2e:9916:0:b0:2d6:f5c6:e5a1 with SMTP id v22-20020a2e9916000000b002d6f5c6e5a1mr13417925lji.12.1713370776971; Wed, 17 Apr 2024 09:19:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE9xTE3bSEYur+3GkSe/swq6fD/fC6KtG5fQWUyYknO7sj6fCON5d6Df+WVtTYJf5TFGqQSfg== X-Received: by 2002:a2e:9916:0:b0:2d6:f5c6:e5a1 with SMTP id v22-20020a2e9916000000b002d6f5c6e5a1mr13417885lji.12.1713370776348; Wed, 17 Apr 2024 09:19:36 -0700 (PDT) Received: from thinky.redhat.com ([109.183.6.197]) by smtp.gmail.com with ESMTPSA id q23-20020a170906a09700b00a519ec0a965sm8243334ejy.49.2024.04.17.09.19.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 09:19:36 -0700 (PDT) From: Andrey Albershteyn To: cem@kernel.org, linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@infradead.org, Andrey Albershteyn , Christoph Hellwig Subject: [PATCH v3 2/3] xfs_db: add helper for flist_find_type for clearer field matching Date: Wed, 17 Apr 2024 18:19:30 +0200 Message-ID: <20240417161931.964526-3-aalbersh@redhat.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240417161931.964526-1-aalbersh@redhat.com> References: <20240417161931.964526-1-aalbersh@redhat.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Make flist_find_type() more readable by unloading field type matching to the helper. Signed-off-by: Andrey Albershteyn Reviewed-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- db/flist.c | 60 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 22 deletions(-) diff --git a/db/flist.c b/db/flist.c index 0a6cc5fcee43..ab0a0f133804 100644 --- a/db/flist.c +++ b/db/flist.c @@ -400,6 +400,40 @@ flist_split( return v; } +static flist_t * +flist_field_match( + const field_t *field, + fldt_t type, + void *obj, + int startoff) +{ + flist_t *fl; + int count; + const ftattr_t *fa; + flist_t *nfl; + + fl = flist_make(field->name); + fl->fld = field; + if (field->ftyp == type) + return fl; + count = fcount(field, obj, startoff); + if (!count) + goto out; + fa = &ftattrtab[field->ftyp]; + if (!fa->subfld) + goto out; + + nfl = flist_find_ftyp(fa->subfld, type, obj, startoff); + if (nfl) { + fl->child = nfl; + return fl; + } + +out: + flist_free(fl); + return NULL; +} + /* * Given a set of fields, scan for a field of the given type. * Return an flist leading to the first found field @@ -413,33 +447,15 @@ flist_find_ftyp( void *obj, int startoff) { - flist_t *fl; const field_t *f; - int count; - const ftattr_t *fa; + flist_t *fl; for (f = fields; f->name; f++) { - fl = flist_make(f->name); - fl->fld = f; - if (f->ftyp == type) + fl = flist_field_match(f, type, obj, startoff); + if (fl) return fl; - count = fcount(f, obj, startoff); - if (!count) { - flist_free(fl); - continue; - } - fa = &ftattrtab[f->ftyp]; - if (fa->subfld) { - flist_t *nfl; - - nfl = flist_find_ftyp(fa->subfld, type, obj, startoff); - if (nfl) { - fl->child = nfl; - return fl; - } - } - flist_free(fl); } + return NULL; } From patchwork Wed Apr 17 16:19:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Albershteyn X-Patchwork-Id: 13633585 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C8C9414D2A4 for ; Wed, 17 Apr 2024 16:19:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713370783; cv=none; b=TFoAQaZuRHiqWhcyiFoeINsXFAfAB+wcqaaCKqw+sS6AU9ofFDAyjgp+W169Vz0Bk9Ja7tSyScEv1VJXP6jiBreM6JabOfNyCM04/Qdlmje5W99IFu2fPDkEYN5rPBI0M8zx7y8RueVObiuauLLoGCzUS36/lYNqtuOlrl2aJF8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713370783; c=relaxed/simple; bh=1E5y44abDRpyALZ+s8e6kXPfcSFzbn2HWIAWc6J+qCw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c1tmSt+1EAIqwx98XKjOBP/18JCc4T6HakS3rh/f7/M9L96RXvJ0eqxYRSqVqxj2l/+0LGdoPhYil97H2Po8CqOjuH+nwAI7t8fK8Pc9Q0guFaSUs6AJjz/eG3mTrm3RVxzGjlqB5htOxN6pz5vGYQ8FOq773t6WQIlRx9XRSv0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=a0zmRr2Z; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="a0zmRr2Z" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1713370780; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3Nzfm18ejw+tnM3xZO6gyjkZvwV4m5FSoUpfxoaN+fA=; b=a0zmRr2ZwvAWqm73ickHxM02dY3GCIE/d2bGVLi4eEZIluYDVUja3BltlYDbOJd9kC5htC 3L7cygEL5gnkiqCa9SHgEi6xtVMg4tvt13ou/zB2gyMisYzw9zmSp5a/FqIeFmj2xzi6Rq Rlkn3/6sXWCAm0iFMH3veDz2AqmkHzg= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-592-u9NeZzXYNv-gjJmoB1JKjQ-1; Wed, 17 Apr 2024 12:19:39 -0400 X-MC-Unique: u9NeZzXYNv-gjJmoB1JKjQ-1 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a52539e4970so261245366b.1 for ; Wed, 17 Apr 2024 09:19:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713370778; x=1713975578; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3Nzfm18ejw+tnM3xZO6gyjkZvwV4m5FSoUpfxoaN+fA=; b=u5eYNFOU3aC1LZexPqbT0x1JFl2vejo4ufJN7pN+CJ1zZ3Ra4ivfIfXeorMuKIdMsc IN5UOmX7Z4uRhec8y635o6/NNy0tnzkCY4mHdV2HbgFhcC17TDki+8vz2RV7dscTyhEH UhkeeG4zv3aqHEvFpkn8eqswjLphPYJlexMCidhBb4Nz5OQDD4/j2Crge5+2/F2v+/LX g4fKH6TtP0GifwyuyqNt3LLsZG9obIph+c9qI5rPydRvu3cGgpaYnwjd+l50J2DTu6Ds 08HiV7W9FucDChrj5ofDCYaHrGB0RmvuA4e9+8Nqne4z0cGDt4waHuNNYy8m4J3JeUH4 alwg== X-Forwarded-Encrypted: i=1; AJvYcCXuJ7lyziNGAVAa2G/uIzAC4bhEQH0pvTSPORgQzUuJHmAeAEH4qS8akKHdOdGDbywRnLSgw18r/E7x0V5cFKmC+Qqz9f+S5U/e X-Gm-Message-State: AOJu0YxN70x/WNDsMxlg8FB/Y7aH/lkWxtLhdNOqwsZnjjpmIXxSFbkP ozuxVft/8lcSTQMGUu/biEusG+LLLzN2iDt5fkft29Y8Q1lmTQUay9c9HSVgA/hhn9NtK1quBTL dly6sANLjjsaank4x/fa3tcbBiPCruod3/eqq/nnqGU6Vk/gaoDMuEAAX X-Received: by 2002:a17:906:c194:b0:a51:982e:b3f7 with SMTP id g20-20020a170906c19400b00a51982eb3f7mr9938181ejz.37.1713370777962; Wed, 17 Apr 2024 09:19:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE27qa3JqyDz0qs3OhX7GrsjPCgbxUszZp3GuTipgylfSsszsf7QYcJePdT8WoqxoS9wVdUtA== X-Received: by 2002:a17:906:c194:b0:a51:982e:b3f7 with SMTP id g20-20020a170906c19400b00a51982eb3f7mr9938169ejz.37.1713370777506; Wed, 17 Apr 2024 09:19:37 -0700 (PDT) Received: from thinky.redhat.com ([109.183.6.197]) by smtp.gmail.com with ESMTPSA id q23-20020a170906a09700b00a519ec0a965sm8243334ejy.49.2024.04.17.09.19.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 09:19:36 -0700 (PDT) From: Andrey Albershteyn To: cem@kernel.org, linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@infradead.org, Andrey Albershteyn , Christoph Hellwig Subject: [PATCH v3 3/3] xfs_repair: catch strtol() errors Date: Wed, 17 Apr 2024 18:19:31 +0200 Message-ID: <20240417161931.964526-4-aalbersh@redhat.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240417161931.964526-1-aalbersh@redhat.com> References: <20240417161931.964526-1-aalbersh@redhat.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 strtol() sets errno if string parsing. Abort and tell user which parameter is wrong. Signed-off-by: Andrey Albershteyn Reviewed-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- repair/xfs_repair.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/repair/xfs_repair.c b/repair/xfs_repair.c index 2ceea87dc57d..2fc89dac345d 100644 --- a/repair/xfs_repair.c +++ b/repair/xfs_repair.c @@ -252,14 +252,22 @@ process_args(int argc, char **argv) if (!val) do_abort( _("-o bhash requires a parameter\n")); + errno = 0; libxfs_bhash_size = (int)strtol(val, NULL, 0); + if (errno) + do_abort( + _("-o bhash invalid parameter: %s\n"), strerror(errno)); bhash_option_used = 1; break; case AG_STRIDE: if (!val) do_abort( _("-o ag_stride requires a parameter\n")); + errno = 0; ag_stride = (int)strtol(val, NULL, 0); + if (errno) + do_abort( + _("-o ag_stride invalid parameter: %s\n"), strerror(errno)); break; case FORCE_GEO: if (val) @@ -272,19 +280,31 @@ process_args(int argc, char **argv) if (!val) do_abort( _("-o phase2_threads requires a parameter\n")); + errno = 0; phase2_threads = (int)strtol(val, NULL, 0); + if (errno) + do_abort( + _("-o phase2_threads invalid parameter: %s\n"), strerror(errno)); break; case BLOAD_LEAF_SLACK: if (!val) do_abort( _("-o debug_bload_leaf_slack requires a parameter\n")); + errno = 0; bload_leaf_slack = (int)strtol(val, NULL, 0); + if (errno) + do_abort( + _("-o debug_bload_leaf_slack invalid parameter: %s\n"), strerror(errno)); break; case BLOAD_NODE_SLACK: if (!val) do_abort( _("-o debug_bload_node_slack requires a parameter\n")); + errno = 0; bload_node_slack = (int)strtol(val, NULL, 0); + if (errno) + do_abort( + _("-o debug_bload_node_slack invalid parameter: %s\n"), strerror(errno)); break; case NOQUOTA: quotacheck_skip(); @@ -305,7 +325,11 @@ process_args(int argc, char **argv) if (!val) do_abort( _("-c lazycount requires a parameter\n")); + errno = 0; lazy_count = (int)strtol(val, NULL, 0); + if (errno) + do_abort( + _("-o lazycount invalid parameter: %s\n"), strerror(errno)); convert_lazy_count = 1; break; case CONVERT_INOBTCOUNT: @@ -356,7 +380,11 @@ process_args(int argc, char **argv) if (bhash_option_used) do_abort(_("-m option cannot be used with " "-o bhash option\n")); + errno = 0; max_mem_specified = strtol(optarg, NULL, 0); + if (errno) + do_abort( + _("%s: invalid memory amount: %s\n"), optarg, strerror(errno)); break; case 'L': zap_log = 1; @@ -377,7 +405,11 @@ process_args(int argc, char **argv) do_prefetch = 0; break; case 't': + errno = 0; report_interval = strtol(optarg, NULL, 0); + if (errno) + do_abort( + _("%s: invalid interval: %s\n"), optarg, strerror(errno)); break; case 'e': report_corrected = true; @@ -397,8 +429,14 @@ process_args(int argc, char **argv) usage(); p = getenv("XFS_REPAIR_FAIL_AFTER_PHASE"); - if (p) + if (p) { + errno = 0; fail_after_phase = (int)strtol(p, NULL, 0); + if (errno) + do_abort( + _("%s: invalid phase in XFS_REPAIR_FAIL_AFTER_PHASE: %s\n"), + p, strerror(errno)); + } } void __attribute__((noreturn))