From patchwork Mon Oct 1 21:28:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yifeng Sun X-Patchwork-Id: 977595 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=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="mNcA5mGW"; dkim-atps=neutral Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42PN95722Jz9sBJ for ; Tue, 2 Oct 2018 12:18:01 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 7527A15CB; Tue, 2 Oct 2018 02:17:59 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 0D15D1448 for ; Tue, 2 Oct 2018 02:17:58 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pg1-f193.google.com (mail-pg1-f193.google.com [209.85.215.193]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 098FAA1E for ; Mon, 1 Oct 2018 21:28:40 +0000 (UTC) Received: by mail-pg1-f193.google.com with SMTP id c10-v6so10364163pgq.4 for ; Mon, 01 Oct 2018 14:28:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=rz32xYmvuYs4YjvuA42C9Y2DsrB/239z8zxhi5MqvmI=; b=mNcA5mGWNpUA4PHjFjOvtjCYlIngJQra49ws7MzWARFjaZJiZIbPBCaiuM/dpPFYRL hn/TILPl5nz9qajBGTbIChGyU5+EqSML25no7wvI1/Y8QZjRQ5rdE06PFhgOamMadomg r3OKjPJL3jz7ejbfwYjuhkxSjH/XIgA5J3hLrYsybg+VJgAqx/9M4d48hn20M9ilXP9f CZZ81M2UDZ3lhNiBmajrSFadkpD+BUMiz85jShfu0MgqzkCvqRwnaNt7kT5+qeQCKPBN S65BJMUQDyjUxVSFwiRMncaICmrQMMoh1+NMzBlV44t0qOpAp3/ceAN0aHme+MCCxVQq Se+Q== 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=rz32xYmvuYs4YjvuA42C9Y2DsrB/239z8zxhi5MqvmI=; b=fwOx6av+2BVKv406zamvcZxyuA3YXxDlE3QDnOwuALNmAf4HnJtprTHLRWdlSezr1l b4ar4UMt3ciCCF7P2hzuBiDIGCaK2hjVfpr0/vaXWadkMhTlGbgMTJlt0QtH4U6tP2AE izfbmC5p6VAxxfjVwpBNaz8vuKsT1CZMv9Feh+OEieN9ABzceBx93dm0hFUuQYU2hn44 erGkuiujM1HJJdvjxohJR0Q4wBtcDpR1HM0Rj6ArhTZYMeprf0ECPTpyUDHqGVe1JEvu t0AZldp6DBP8diMNDW5aFC9MkiGLRQkEGJSGCKtUgtoT1igdc3fi86+KThHqFLARJt1P MXZw== X-Gm-Message-State: ABuFfoiVCPMzeK9WZbwPxhpVrp3f+bu3SoDJTViQxIu1RLl2LjlWeueq kHEu24bZejVZ7BGWgGlxT66LZTbl X-Google-Smtp-Source: ACcGV60Zybvk1gzUQarrktQ2nuqM1SyQq4TXeIaQ7NEnhsTiEjmwMTAHYyjt7e9tEyWGXkft17WIsw== X-Received: by 2002:a17:902:1ea:: with SMTP id b97-v6mr12541735plb.152.1538429320328; Mon, 01 Oct 2018 14:28:40 -0700 (PDT) Received: from kern417.eng.vmware.com ([66.170.99.1]) by smtp.gmail.com with ESMTPSA id c28-v6sm32313377pfk.48.2018.10.01.14.28.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 01 Oct 2018 14:28:39 -0700 (PDT) From: Yifeng Sun To: dev@openvswitch.org Date: Mon, 1 Oct 2018 14:28:33 -0700 Message-Id: <1538429313-6818-1-git-send-email-pkusunyifeng@gmail.com> X-Mailer: git-send-email 2.7.4 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH] expr: Properly initialize expr_constant X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org expr_constant.masked may be uninitialized when its type is EXPR_C_STRING. This patch fixes this issue. Reported-at: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=10731 Signed-off-by: Yifeng Sun --- include/ovn/expr.h | 10 +++++++++- ovn/lib/expr.c | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/include/ovn/expr.h b/include/ovn/expr.h index 3995e62f066c..8d3cab399bf0 100644 --- a/include/ovn/expr.h +++ b/include/ovn/expr.h @@ -450,7 +450,9 @@ enum expr_constant_type { EXPR_C_STRING }; -/* A string or integer constant (one must know which from context). */ +/* A string or integer constant (one must know which from context). + * It should be initialized through expr_constant_init(). + */ union expr_constant { /* Integer constant. * @@ -469,6 +471,12 @@ union expr_constant { char *string; }; +static inline void +expr_constant_init(union expr_constant *c) +{ + memset(c, 0, sizeof *c); +} + bool expr_constant_parse(struct lexer *, const struct expr_field *, union expr_constant *); void expr_constant_format(const union expr_constant *, diff --git a/ovn/lib/expr.c b/ovn/lib/expr.c index 148ac869e861..0a2cef2f0ee9 100644 --- a/ovn/lib/expr.c +++ b/ovn/lib/expr.c @@ -805,6 +805,7 @@ parse_constant(struct expr_context *ctx, struct expr_constant_set *cs, } union expr_constant *c = &cs->values[cs->n_values++]; + expr_constant_init(c); c->value = ctx->lexer->token.value; c->format = ctx->lexer->token.format; c->masked = ctx->lexer->token.type == LEX_T_MASKED_INTEGER; @@ -1004,6 +1005,7 @@ expr_const_sets_add(struct shash *const_sets, const char *name, values[i], lex.token.type); } else { union expr_constant *c = &cs->values[cs->n_values++]; + expr_constant_init(c); c->value = lex.token.value; c->format = lex.token.format; c->masked = lex.token.type == LEX_T_MASKED_INTEGER; @@ -1017,6 +1019,7 @@ expr_const_sets_add(struct shash *const_sets, const char *name, cs->type = EXPR_C_STRING; for (size_t i = 0; i < n_values; i++) { union expr_constant *c = &cs->values[cs->n_values++]; + expr_constant_init(c); c->string = xstrdup(values[i]); } } @@ -1120,6 +1123,7 @@ expr_parse_primary(struct expr_context *ctx, bool *atomic) *atomic = true; union expr_constant *cst = xzalloc(sizeof *cst); + expr_constant_init(cst); cst->format = LEX_F_HEXADECIMAL; cst->masked = false;