From patchwork Thu Jun 17 19:43:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claire Jensen X-Patchwork-Id: 12329425 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44374C2B9F4 for ; Thu, 17 Jun 2021 19:43:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 28D416113E for ; Thu, 17 Jun 2021 19:43:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232881AbhFQTpt (ORCPT ); Thu, 17 Jun 2021 15:45:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232227AbhFQTpt (ORCPT ); Thu, 17 Jun 2021 15:45:49 -0400 Received: from mail-io1-xd49.google.com (mail-io1-xd49.google.com [IPv6:2607:f8b0:4864:20::d49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CD0CC061574 for ; Thu, 17 Jun 2021 12:43:41 -0700 (PDT) Received: by mail-io1-xd49.google.com with SMTP id l15-20020a5e820f0000b02904bd1794d00eso2611520iom.7 for ; Thu, 17 Jun 2021 12:43:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=9LDbOaEM/a3Zk5QAnW9wytp6LFTh5fwBPEta0qyfK50=; b=djnP/IjMfGuifSAuqxZUXuEIKHzP3vVsAuPN5V/ufDlDj0CM86Ev4SUbyUVEshgf3m 5hfV7jcnJTXNJd8eadsvKvKz3nYe6DGsjgyD6KywQ7uba+NDSy8AF1imMvuug1GHjXWg A8ZmeIU9lmj+oz8meCImEWuG2/c93w5y39pJyw7LeuCMjB4GK/mWICeSbJfqngtwoT/P nqeGn4r/YfMiBf14PeELvs7+ftkMalwNS7Kh3A4Sd4VYnxChUzBVg6/0BQWuqHFnSgFh WUcDz/kQvQS3FjxEivrStMLG6WaMuWk+pToph3UoLy5fIWYMKkbhXmtSwXE8LpgRlsh4 5Jfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=9LDbOaEM/a3Zk5QAnW9wytp6LFTh5fwBPEta0qyfK50=; b=lyJIr2SmC9KrsZpz/PO/dfEjb0CcVAFgB/QDuRYUjDexmj1AjMuoN8hWAZBal47GPU D40MSVaItWD6y5KjsgkcR593QYr9WvJj5nObwCcJnt1X+QiHSrNSTze9df7KxSwCcqxA QJJXqj261htsyJau5GXj46UQdIEee8zwoQ41OPFz9GecTGC/tscCl6zVj4Vpv7aCOobO v1jxMrcCkJ1S0NqU8caCxv/jyRD0EJqV4f8K89CYe9CkRFuxfvVLq+A+K+e+/1EnqYek UjHs1FrYATs+ydXWLSvu4Gm0yR3Mq0gxvoaHewKpiQV2XfsmqAHyr14+1ftpaMsVi1uA wgBg== X-Gm-Message-State: AOAM533QNL4x+RRjr57ViMeeJI8ZteIJLKQQyJZvCnrlySmVPiGmguSi IJyyXhb0pnNfpxZFKd0ztEFkadf1OJM= X-Google-Smtp-Source: ABdhPJxvrWPoICOGYxorzH4NDpCEGJHaF7uhQz2VyB6IpqenRteYu+jFiACdnjFUJxbCJCff/To12bORbNM= X-Received: from cjense.c.googlers.com ([fda3:e722:ac3:10:2b:ff92:c0a8:6d0]) (user=cjense job=sendgmr) by 2002:a05:6638:140c:: with SMTP id k12mr6380617jad.126.1623959020777; Thu, 17 Jun 2021 12:43:40 -0700 (PDT) Date: Thu, 17 Jun 2021 19:43:25 +0000 Message-Id: <20210617194326.2107129-1-cjense@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.32.0.288.g62a8d224e6-goog Subject: [PATCH 1/2] libtraceevent: Add eof checks. From: Claire Jensen To: eranian@google.com, irogers@google.com, tz.stoyanov@gmail.com, linux-trace-devel@vger.kernel.org, rostedt@goodmis.org Cc: Claire Jensen Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Added checking for __read_char and peek_char to make sure value is not at end of file. This issue was found while fuzz testing. One of the test cases created an infinite loop because __read_token had reached end of file. Checking was added to all cases where this may occur. Signed-off-by: Claire Jensen --- src/event-parse.c | 62 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 14 deletions(-) diff --git a/src/event-parse.c b/src/event-parse.c index 97c1a97..f454e23 100644 --- a/src/event-parse.c +++ b/src/event-parse.c @@ -1155,17 +1155,16 @@ static enum tep_event_type force_token(const char *str, char **tok); static enum tep_event_type __read_token(char **tok) { char buf[BUFSIZ]; - int ch, last_ch, quote_ch, next_ch; + int ch, last_ch, quote_ch, next_ch, read_ch, peek_ch; int i = 0; int tok_size = 0; enum tep_event_type type; *tok = NULL; - - ch = __read_char(); + ch = __read_char(); if (ch < 0) - return TEP_EVENT_NONE; + goto out_eof_error; type = get_type(ch); if (type == TEP_EVENT_NONE) @@ -1184,9 +1183,15 @@ static enum tep_event_type __read_token(char **tok) case TEP_EVENT_OP: switch (ch) { case '-': - next_ch = peek_char(); + peek_ch = peek_char(); + if (peek_ch < 0) + goto out_eof_error; + next_ch = peek_ch; if (next_ch == '>') { - buf[i++] = __read_char(); + read_ch = __read_char(); + if (read_ch < 0) + goto out_eof_error; + buf[i++] = read_ch; break; } /* fall through */ @@ -1197,9 +1202,14 @@ static enum tep_event_type __read_token(char **tok) case '<': last_ch = ch; ch = peek_char(); + if (ch < 0) + goto out_eof_error; if (ch != last_ch) goto test_equal; - buf[i++] = __read_char(); + read_ch = __read_char(); + if (read_ch < 0) + goto out_eof_error; + buf[i++] = read_ch; switch (last_ch) { case '>': case '<': @@ -1219,10 +1229,17 @@ static enum tep_event_type __read_token(char **tok) return type; test_equal: - ch = peek_char(); - if (ch == '=') - buf[i++] = __read_char(); - goto out; + peek_ch = peek_char(); + if (peek_ch < 0) + goto out_eof_error; + ch = peek_ch; + if (ch == '=') { + read_ch = __read_char(); + if (read_ch < 0) + goto out_eof_error; + buf[i++] = read_ch; + goto out; + } case TEP_EVENT_DQUOTE: case TEP_EVENT_SQUOTE: @@ -1242,6 +1259,8 @@ static enum tep_event_type __read_token(char **tok) } last_ch = ch; ch = __read_char(); + if(ch < 0) + goto out_eof_error; buf[i++] = ch; /* the '\' '\' will cancel itself */ if (ch == '\\' && last_ch == '\\') @@ -1259,6 +1278,8 @@ static enum tep_event_type __read_token(char **tok) do { ch = __read_char(); + if(ch < 0) + return TEP_EVENT_NONE; } while (isspace(ch)); if (ch == '"') goto concat; @@ -1273,7 +1294,13 @@ static enum tep_event_type __read_token(char **tok) break; } - while (get_type(peek_char()) == type) { + while (1) { + peek_ch = peek_char(); + if (peek_ch < 0) + goto out_eof_error; + if (get_type(peek_ch) != type) + break; + if (i == (BUFSIZ - 1)) { buf[i] = 0; tok_size += BUFSIZ; @@ -1282,8 +1309,10 @@ static enum tep_event_type __read_token(char **tok) return TEP_EVENT_NONE; i = 0; } - ch = __read_char(); - buf[i++] = ch; + read_ch = __read_char(); + if (read_ch < 0) + goto out_eof_error; + buf[i++] = read_ch; } out: @@ -1316,6 +1345,11 @@ static enum tep_event_type __read_token(char **tok) } return type; + +out_eof_error: + free(*tok); + *tok = NULL; + return TEP_EVENT_NONE; } static enum tep_event_type force_token(const char *str, char **tok) From patchwork Thu Jun 17 19:43:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claire Jensen X-Patchwork-Id: 12329427 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B5B82C49361 for ; Thu, 17 Jun 2021 19:43:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9BF32613D5 for ; Thu, 17 Jun 2021 19:43:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229842AbhFQTqD (ORCPT ); Thu, 17 Jun 2021 15:46:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231186AbhFQTqC (ORCPT ); Thu, 17 Jun 2021 15:46:02 -0400 Received: from mail-il1-x14a.google.com (mail-il1-x14a.google.com [IPv6:2607:f8b0:4864:20::14a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABD9EC061574 for ; Thu, 17 Jun 2021 12:43:54 -0700 (PDT) Received: by mail-il1-x14a.google.com with SMTP id y6-20020a92d0c60000b02901e82edc2af9so4531689ila.13 for ; Thu, 17 Jun 2021 12:43:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=fuaV1+ObE76hPBSxwnJ1+z4E0ooCaUAA9Jdria1q0FA=; b=srimWNqnwQeG0ZgnofYTFvSgXATBGLE8SrRwTcvV7adXQ3fyzbDY1aznQnx2HHmHn5 T9vzpJbq30Pn8P0KbVFBf70HF6n/KggCXEvWdStYUQUinyQFfK0yF9iWrcR2/cmJaRpg wyrcKK0IR0oGNl008PttQHkQhSv0CXDzgLLzKv7P73VOYuoLRZUMImmxKgcQci3jAMuq cjzUNQGNH1lF8Y2eu2zicqz33nApy9TALfSuwpqrGExNmitDG4IqULg6zkAwQZTKIWJr +w7XZyOyvNA0+iu/Rnd2L+HFnRs0drLk38L97fLO1PM4hzE8Ojxdyu6SiZqJU/lRUsXR JosA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=fuaV1+ObE76hPBSxwnJ1+z4E0ooCaUAA9Jdria1q0FA=; b=VDhzWFjJ7nVlNx5JBxwF16Q/8gS93THtiM+BgYH0yaoHG1iYC97LTtQwmun65S1H1E 9AebwfdRaWaCuFTyzVZHnLQ3yF4+H+NAvqB0HaSXVkYWT0JiMsges7QqziL8j4oxhBrC T8r2aG78/dItzRAYuZ3hVcI/e3svtg5/fjZDSX2LJ8AnFTzT/WHj/Zu1krpBqSlPu54O r8ak9hTPhPiEVEPClGJ5VHNx1TCzeXYFXapRDuEtJhKPiLUfPnXNAzmpgjfWoaueeZlQ 8RSRMYy0xbGQJxQkA9eQ5SpjER3t88UtWmJTXxLvE+S5axaSNhEkSvc+fdLlEcccz5SN qWag== X-Gm-Message-State: AOAM532DmUbO2KghqHpmuxBYufw9sScaKYvRHfU1FjJ9tZMvT+FNHxFO DeQtTZSkJ0KLCYAKyX1GnD0+EebCt9s= X-Google-Smtp-Source: ABdhPJwqTbESR/5JnaRfcY83GN8n6965ET7IzRhy8Mr+jC142G/iDQP2zwoeDKkwqwcr2sRNOiBjF+nrh+4= X-Received: from cjense.c.googlers.com ([fda3:e722:ac3:10:2b:ff92:c0a8:6d0]) (user=cjense job=sendgmr) by 2002:a6b:4e0a:: with SMTP id c10mr5003916iob.183.1623959034074; Thu, 17 Jun 2021 12:43:54 -0700 (PDT) Date: Thu, 17 Jun 2021 19:43:26 +0000 In-Reply-To: <20210617194326.2107129-1-cjense@google.com> Message-Id: <20210617194326.2107129-2-cjense@google.com> Mime-Version: 1.0 References: <20210617194326.2107129-1-cjense@google.com> X-Mailer: git-send-email 2.32.0.288.g62a8d224e6-goog Subject: [PATCH 2/2] libtraceevent: Changed angled brackets to double quotes. From: Claire Jensen To: eranian@google.com, irogers@google.com, tz.stoyanov@gmail.com, linux-trace-devel@vger.kernel.org, rostedt@goodmis.org Cc: Claire Jensen Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Certain build systems, such as bazel, are picky about angled brackets vs double quotes. the failure you see when building is: In file included from src/event-parse.c:27: src/event-utils.h:13:10: error: 'event-parse.h' file not found with include; use "quotes" instead #include ^~~~~~~~~~~~~~~ "event-parse.h" Arguably -iquote is more correct within the library build, hence bazel using it. The libtraceevent Makefile is using -I, hence this not being a problem for others. Signed-off-by: Claire Jensen --- src/event-utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/event-utils.h b/src/event-utils.h index d377201..44f7968 100644 --- a/src/event-utils.h +++ b/src/event-utils.h @@ -10,7 +10,7 @@ #include #include -#include +#include "event-parse.h" void tep_warning(const char *fmt, ...); void tep_info(const char *fmt, ...);