From patchwork Mon Nov 27 07:18:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 10075973 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 90C426028E for ; Mon, 27 Nov 2017 07:18:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8273328CF2 for ; Mon, 27 Nov 2017 07:18:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 76E7328D08; Mon, 27 Nov 2017 07:18:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 036D928D19 for ; Mon, 27 Nov 2017 07:18:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751445AbdK0HSW (ORCPT ); Mon, 27 Nov 2017 02:18:22 -0500 Received: from mail-pg0-f68.google.com ([74.125.83.68]:44260 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750838AbdK0HSV (ORCPT ); Mon, 27 Nov 2017 02:18:21 -0500 Received: by mail-pg0-f68.google.com with SMTP id c123so18289361pga.11; Sun, 26 Nov 2017 23:18:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=amXE+kcCt6rvKq7muq+nfHsTowFEefFf4FNc3UkB3OM=; b=hGHHA5JjMYz5hAWn7YFCRvR9fGFqO+1XqJqY3734/8m4wvLHSFULFCDZCw9yUVDhBR N5gZz5L7dFNdyGauPc0p8pVLHFlGr5CkRnZfDaIjQ+PePHZkZVe0iMMQmS2WcdMbIpwk Z1SA89nk5Df0J4pZbThOTZLg43pfIuHTuZpBS6wKO48Q16+KN9+xjlYVgNrErPMODtv3 aNk8VGMYo9Jo5JnLooT/34fjAOB9FomH/EZpJt1VrQFsjLqOh/aF910CE9jWXeXV/mNj jvi09xwqP9rn6tFuKwizK+bmrIDH/Ie1i4A/t4U7OA5Nzq0eqy+/pHZVBwmkbHDX0xN6 BOHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=amXE+kcCt6rvKq7muq+nfHsTowFEefFf4FNc3UkB3OM=; b=GHv9BdrpMfYrXN9y57LpTDnJCo4DA+0dVR445RYy9vEzFp7fH6c4rwh+TJPtXJzBXq o/lArhva9dyiS/JfahM9DXvRbvMcRmabnQaTApcNERWPRhkLei7/oq9xBhs/oNowQ47q zbFP7qIRrMBWPxwNg3fFwFCg4Ov3tLVDhhsQ4ar2d3+k6YV6VKEl6QIsSA+5T0omkLHA OKuK6W646gMYav4RxwQ79Xp02eHE+enjedwG7g7f+UM3bVpuN6WtWw6lM/kbET8lv3s7 9lezx8wu/KtJcZkFsv1YAAk0z2MtPPawRdaLTOXxmbpTBQA47SN4jm00oMsfX8NDGztZ vLpg== X-Gm-Message-State: AJaThX4Ix7mm4iSKcRoy12YLvZa7mpoROK2g5Hp1rspqj2ityAfmaN29 iukhe6MRn0gTadmkLY5Kceq48Cgb X-Google-Smtp-Source: AGs4zMZG17xKaoBJXvQqdIYVZ2NhFRYGrQIpuNQeLJRgstfigIobyFz8t5bpdelHPl/u4JRAYihXQQ== X-Received: by 10.98.65.84 with SMTP id o81mr27650632pfa.55.1511767100651; Sun, 26 Nov 2017 23:18:20 -0800 (PST) Received: from zzz.localdomain (c-67-185-97-198.hsd1.wa.comcast.net. [67.185.97.198]) by smtp.gmail.com with ESMTPSA id n129sm46720449pfn.1.2017.11.26.23.18.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 Nov 2017 23:18:20 -0800 (PST) From: Eric Biggers To: keyrings@vger.kernel.org, David Howells Cc: linux-crypto@vger.kernel.org, Alexander Potapenko , Eric Biggers , Takashi Iwai Subject: [PATCH] X.509: fix printing uninitialized stack memory when OID is empty Date: Sun, 26 Nov 2017 23:18:17 -0800 Message-Id: <20171127071817.25999-1-ebiggers3@gmail.com> X-Mailer: git-send-email 2.15.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Eric Biggers Callers of sprint_oid() do not check its return value before printing the result. In the case where the OID is zero-length, -EBADMSG was being returned without anything being written to the buffer, resulting in uninitialized stack memory being printed. Fix this by writing "(empty)" to the buffer in that case. Fixes: 4f73175d0375 ("X.509: Add utility functions to render OIDs as strings") Cc: Takashi Iwai Signed-off-by: Eric Biggers --- lib/oid_registry.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/oid_registry.c b/lib/oid_registry.c index 5a75d127995d..3640170f0d65 100644 --- a/lib/oid_registry.c +++ b/lib/oid_registry.c @@ -115,8 +115,10 @@ int sprint_oid(const void *data, size_t datasize, char *buffer, size_t bufsize) size_t ret; int count; - if (v >= end) + if (v >= end) { + snprintf(buffer, bufsize, "(empty)"); return -EBADMSG; + } n = *v++; ret = count = snprintf(buffer, bufsize, "%u.%u", n / 40, n % 40);