From nobody Tue Feb 10 16:22:37 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1611937144; cv=none; d=zohomail.com; s=zohoarc; b=H/f8wG761RgpbNPXkE9nNxOz7z19fLwJGE8GbV7u8lntQqsHzH6unKEtglft6UF2qPy/vAM5rxBYVC6y7OSldFNVcNpkNKqYOMGUMEdf9KCbhKp9L/TFYB4Askbp4WqphdqCtynmjRengAvq/gPWlSyYNLTfto3ChyuoKFjLn0w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611937144; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Tl38d20OfW5zIZOCKs3zzKGiET2pfxC3AmOaMADoszc=; b=nGwsA8ZtW+cEGktXg/CsJW0x+kEGZ1G9gq7+vtB0TEPzf+FtYVjkVOriqiAloWojqUoUhaUft/HHeR/geVPYJgXTeWXUgl0Fc9SRhA3NVlxRdXia8Uv23gXEd9yggkqEuGYP8eAc7hoFQLO4EXCQzKVhqRtBI1i5DDHHbkNE/+Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1611937144449238.42584194994777; Fri, 29 Jan 2021 08:19:04 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-55-gQmf1Y-OMp22sjXLJhLE6w-1; Fri, 29 Jan 2021 11:17:42 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 07B9B8735DA; Fri, 29 Jan 2021 16:17:31 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D82D860BE2; Fri, 29 Jan 2021 16:17:30 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 9DA721809CA0; Fri, 29 Jan 2021 16:17:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10TGHPpH010665 for ; Fri, 29 Jan 2021 11:17:25 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2115D60C5E; Fri, 29 Jan 2021 16:17:25 +0000 (UTC) Received: from work.redhat.com (ovpn-113-143.ams2.redhat.com [10.36.113.143]) by smtp.corp.redhat.com (Postfix) with ESMTP id 64B0560CC4; Fri, 29 Jan 2021 16:17:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611937143; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Tl38d20OfW5zIZOCKs3zzKGiET2pfxC3AmOaMADoszc=; b=ZKjbj6BgqiMAvuxxNlZDBOG0j5DFNdWo3LxziyWFpIURixDN5M8RqWTJn6DNhp6VgjnDDR OJjDlnUx7g68ek19OgGKxSvaIUeHL3R1/M1c4FU91xAWvLa3C5K7VqIRQvbtBSBIDFU+5s O6W/XN09bKGVnOMiqn8/xv3Kz7uzfSk= X-MC-Unique: gQmf1Y-OMp22sjXLJhLE6w-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 14/19] commandhelper: Make number of fds variable in printInput Date: Fri, 29 Jan 2021 17:16:24 +0100 Message-Id: <20210129161629.604823-15-twiederh@redhat.com> In-Reply-To: <20210129161629.604823-1-twiederh@redhat.com> References: <20210129161629.604823-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Fixes a buffer overflow triggered when more than three "--readfd" arguments were given on the command line. Signed-off-by: Tim Wiederhake --- tests/commandhelper.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/tests/commandhelper.c b/tests/commandhelper.c index d501e33e88..72a3e89da1 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -194,13 +194,22 @@ static int printCwd(FILE *log) static int printInput(struct Arguments *args) { char buf[1024]; - struct pollfd fds[3]; - char *buffers[3] =3D {NULL, NULL, NULL}; - size_t buflen[3] =3D {0, 0, 0}; + struct pollfd *fds =3D NULL; + char **buffers =3D NULL; + size_t *buflen =3D NULL; int ret =3D -1; size_t i; ssize_t got; =20 + if (!(fds =3D calloc(args->numreadfds, sizeof(*fds)))) + goto cleanup; + + if (!(buffers =3D calloc(args->numreadfds, sizeof(*buffers)))) + goto cleanup; + + if (!(buflen =3D calloc(args->numreadfds, sizeof(*buflen)))) + goto cleanup; + if (args->close_stdin) { if (freopen("/dev/null", "r", stdin) !=3D stdin) goto cleanup; @@ -282,8 +291,14 @@ static int printInput(struct Arguments *args) ret =3D 0; =20 cleanup: - for (i =3D 0; i < G_N_ELEMENTS(buffers); i++) - free(buffers[i]); + if (buffers) { + for (i =3D 0; i < args->numreadfds; i++) + free(buffers[i]); + } + free(fds); + free(buflen); + free(buffers); + return ret; } =20 --=20 2.26.2