From patchwork Thu Feb 7 10:53:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 1037960 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=vivier.eu Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43wFZF5YcWz9sN6 for ; Thu, 7 Feb 2019 21:54:45 +1100 (AEDT) Received: from localhost ([127.0.0.1]:37728 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grhKN-0004fG-KX for incoming@patchwork.ozlabs.org; Thu, 07 Feb 2019 05:54:43 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43763) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grhJq-0004eC-At for qemu-devel@nongnu.org; Thu, 07 Feb 2019 05:54:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grhJp-00089Q-IH for qemu-devel@nongnu.org; Thu, 07 Feb 2019 05:54:10 -0500 Received: from mout.kundenserver.de ([212.227.17.13]:40003) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1grhJn-00087R-Ga for qemu-devel@nongnu.org; Thu, 07 Feb 2019 05:54:08 -0500 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue107 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MOzjW-1gSTKn26cW-00PMAU; Thu, 07 Feb 2019 11:53:53 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Thu, 7 Feb 2019 11:53:46 +0100 Message-Id: <20190207105347.22337-3-laurent@vivier.eu> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190207105347.22337-1-laurent@vivier.eu> References: <20190207105347.22337-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:ogu536TaEctVGVuCCHnVgd++/KjyT9FiVgdRf0RB64B3ktg0mD/ kHXSud4jXCeZJJ4y2NMADGbBINRGE3+BANbb4YMnf5hu+dFcSDdv02/snxlSrEJ5rjPX2LH T5Srv4lW6njza2xHqOtH73Oyr+vUyhDjzE4jpMoHcVjUM5Tb2pxuwK9/W8NvjyWv+64CF0I 8uw4MAzyClAHBFzHKD0KQ== X-UI-Out-Filterresults: notjunk:1; V03:K0:sgM+yuulIV0=:inHU+O6Ig3q2ECUgjOkLfu EVRtUTucYj1pM/Db+XEEZuOefClJD2dtJSuTX9gpCZ5TNRmiEyD7hJKwBR3khjeqxheID7Wzx B+1sbl2MtzqD2dydpTTdalUkKAFKl7Xe624hfd5vQITEyMBMFDUiIpikl3/q3Oqt6/+szYyPN YyDW03vtcYyi42O/lfdj2GR3aqvGL0nAk9E0u2UWmEm94REGcaJcK4Y44uT06I+7hdaT8qZ31 bGCTVALXibzFzcHcozrqIDK/JUMu7ZQN0Edd3+q21KkZrt++lDhrbCFcIVRJ9OReimpb6vHWJ qXiP6rgyLJJjxuA/qbFOBZFjWVnf9totm9tAUmRcmS5T7SM15IKBFW2regXK+GiSZJJhuSeZm ND26rtDBJgaZkatDJuPL53oVCywTSKzi1/5ikKxc6FUdsmcOjN5sUby17aY3NxM4v8gzw9urC uh2ThJlmTIPo7Cx5TYCrx3/QZxa8cro40Dsq1YM/Rj/gur5hGKumrhUNDRQi6F2s1/xspm4J1 DB87FULtifb2t1Zr+lShHHBQ8N5BIRWt4vWdAh4ETWY7mS7cpFpbEE/wj20c2aSJ/mUlj0kln LGoa4oTQQYTpgNBOuSJeUZ6jjHomOL+puG+YJrZwKHRyN0Vdp0FRaxi9c3WXpb4ZNEau4VoMf frQeXjQ5TE09qPw5hR1tLYMbBqoe65G0NiX2tkqGolSoBM0ati5O2taSBD/YJGA3QUoBlF9gv CgjOnIVayZTKA9olu53/IMLp7AiVVzT5KEhvdq+iKTxg5kNP/W67Fcb3I2Q= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.17.13 Subject: [Qemu-devel] [PULL 2/3] linux-user: Check sscanf return value in open_net_route() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Riku Voipio , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= , Laurent Vivier , Stefano Garzarella Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell Coverity warns (CID 1390634) that open_net_route() is not checking the return value from sscanf(), which means that it might then use values that aren't initialized. Errors here should in general not happen since we're passing an assumed-good /proc/net/route from the host kernel, but if we do fail to parse a line then just skip it in the output we pass to the guest. Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Stefano Garzarella Reviewed-by: Laurent Vivier Message-Id: <20190205174207.9278-1-peter.maydell@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 5b9d75fbb4..a69c734aa0 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -6767,9 +6767,15 @@ static int open_net_route(void *cpu_env, int fd) char iface[16]; uint32_t dest, gw, mask; unsigned int flags, refcnt, use, metric, mtu, window, irtt; - sscanf(line, "%s\t%08x\t%08x\t%04x\t%d\t%d\t%d\t%08x\t%d\t%u\t%u\n", - iface, &dest, &gw, &flags, &refcnt, &use, &metric, - &mask, &mtu, &window, &irtt); + int fields; + + fields = sscanf(line, + "%s\t%08x\t%08x\t%04x\t%d\t%d\t%d\t%08x\t%d\t%u\t%u\n", + iface, &dest, &gw, &flags, &refcnt, &use, &metric, + &mask, &mtu, &window, &irtt); + if (fields != 11) { + continue; + } dprintf(fd, "%s\t%08x\t%08x\t%04x\t%d\t%d\t%d\t%08x\t%d\t%u\t%u\n", iface, tswap32(dest), tswap32(gw), flags, refcnt, use, metric, tswap32(mask), mtu, window, irtt);