From patchwork Sat Jun 12 01:45:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12316809 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 D35BEC48BE6 for ; Sat, 12 Jun 2021 01:46:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B1310613AA for ; Sat, 12 Jun 2021 01:46:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230334AbhFLBsW (ORCPT ); Fri, 11 Jun 2021 21:48:22 -0400 Received: from mail-qv1-f74.google.com ([209.85.219.74]:47825 "EHLO mail-qv1-f74.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229622AbhFLBsV (ORCPT ); Fri, 11 Jun 2021 21:48:21 -0400 Received: by mail-qv1-f74.google.com with SMTP id k12-20020a0cfd6c0000b029020df9543019so21207775qvs.14 for ; Fri, 11 Jun 2021 18:46:08 -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=rrlxkzMGYbwZAawadCfXs+exPN694DZ/BrWu5hxPo+E=; b=QGVA4Zk0WCXJM+Tqngkn38btUfClYB8VHMVeYBms75BTjLNgo5Y7vN/dzNyYB7fWxl bbW+XlD1V+QQRxqtoMnZLkdPvT8M38MJ9g72sx571wMpcKtROZz0DWTKtun+1K9K+S8r Q48tb9kfyZxXQRrBNbG1w5O2r210+eiA8dpIWr/3V6QIwR3XxPgEo4NxhUvx2oKXPrxT 9wExMLBDCyTQ8WdbXyClYbutBaCAAhebhc/MbSNjwnd1nJ7Wgb94T9Wl2yzfmOtwE6ft N9IMIUvdAhFk8rRYOVjPBPinUyrXsHqpx783+oQAKqiRrBGuRr2Ps6krJ4ET/0JmJCva w7qA== 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=rrlxkzMGYbwZAawadCfXs+exPN694DZ/BrWu5hxPo+E=; b=NxUtlCbu4ZIeTa8HaoEOhBtq2RMnVPXByRqDQ58KrwAYra5NkZ1Y9NfhoEfGUiwNi/ IT1rpXc+eYU9lKrQQ9bsL4MOXRPfSRqlFY+zuOXK66O+7+T0/MZxmSpBX1sf4wWgR6T+ 6yp2LtVriuraCVE3m2Z1qwgy20sabcgD2FiMNZA6DFOW/LZUpXTMKusqjoIqdE1+umoO VyXNrABxZiu6B6n2YscXsIe4RuTrb7txUbYNEEW+aiYxbpxz0NHy3N2WsX3ZqJprzdrI adIoPvfhH1MDMvL9Gj/1YjRavpZoUelQgH8lYAkXtaV9DZN3g45QCM6egEeF/gnNkQ0E DUeQ== X-Gm-Message-State: AOAM530vCXXf/lXvlL+jJzxJGgd+U5gWKvyag6V0X+xfbR2ISo4ksXbh 4StVMGAxgSA7/p6h6kcXJnhK1gGWAFVbY0VY+KFq2YkP2Kg103SYHmUoJZOgbSigNGYwgZdIVQ4 ShOKIK/kG0JPCvnGJl/pJQN9lzJUvYJA6iZbGlEppCBFmPspND5Yftrjudoxm/SppU4pC1KiIcm NDSZM= X-Google-Smtp-Source: ABdhPJyJeKGuAM+f+oC1mJwpEscGRjrSpA3wdi9MJJxOcozkLO6CN/X2NS+s/eRaLZ6WWILONg+O51Dk4KwQ X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:27c2:28ad:b3af:418a]) (user=irogers job=sendgmr) by 2002:a05:6214:485:: with SMTP id ay5mr7805347qvb.6.1623462307598; Fri, 11 Jun 2021 18:45:07 -0700 (PDT) Date: Fri, 11 Jun 2021 18:45:00 -0700 In-Reply-To: <20210612014501.890593-1-irogers@google.com> Message-Id: <20210612014501.890593-2-irogers@google.com> Mime-Version: 1.0 References: <20210612014501.890593-1-irogers@google.com> X-Mailer: git-send-email 2.32.0.272.g935e593368-goog Subject: [PATCH 1/2] libtraceevent: Add eof checks. From: Ian Rogers To: linux-trace-devel@vger.kernel.org, Tzvetomir Stoyanov , Steven Rostedt , Claire Jensen Cc: Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org From: Claire Jensen Added checking for __read_char and peek_char to make sure value is not at end of file. Signed-off-by: Claire Jensen Signed-off-by: Ian Rogers --- 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 9915cb4..ac11887 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 Sat Jun 12 01:45:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12316811 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 24001C48BE5 for ; Sat, 12 Jun 2021 01:46:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0CE766128A for ; Sat, 12 Jun 2021 01:46:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229622AbhFLBsW (ORCPT ); Fri, 11 Jun 2021 21:48:22 -0400 Received: from mail-qv1-f73.google.com ([209.85.219.73]:33717 "EHLO mail-qv1-f73.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230332AbhFLBsW (ORCPT ); Fri, 11 Jun 2021 21:48:22 -0400 Received: by mail-qv1-f73.google.com with SMTP id dr11-20020a05621408ebb029021e40008bd5so22724081qvb.0 for ; Fri, 11 Jun 2021 18:46:10 -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=2d6F0jWxV3WmN3WXrDucXjgB6Iyj+9cQ0Z88+2tSQ6Q=; b=hxOe6SVsI3g88RGrgHYHEp2oVtSF3ZsJqYpdOyBqEOIygjpadVCcLxD72oLsrd5HLE SoRMDuSsHITuiR+IeMSjV6VTQ4pqaP/ee/ExPU/6MGilvukRE6s/DA1+wbDpi4GpygI8 ElmseX8PkILAF7cQcV+1/+GH14avaTLnAUUg5b1y7LmSgsQNQJsyVHTR+OIr3GHWVMLx TCExyWlHLJyDuzkmv5N3fXb0jfsbr7zN/a2pYKYLH/ZlefRM4mfZWL5uoMPHSoNA4cn6 k0LSfsN73QdrpNPDBG82aA1E8UZuZAdLZRs1m79YJGvqV9mgOhYI1VuyT3s92Lcg/Ngv Lj1A== 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=2d6F0jWxV3WmN3WXrDucXjgB6Iyj+9cQ0Z88+2tSQ6Q=; b=cNIfVsmBQMBTdAtAbEHVMtrwy9DK60v1pJR3cT2sfFbx9a9P8CDdV4rnb1wcPNxn6+ 59ETMlbT94rcgdIOLUKslP9CZPQavMqfpy0o70LWEmPEbYT6SV0ftZAAHU2barT1tXJV KVHL/GNP/eNVkBn2ed4d44R6CuL2C8vJNNFDpiYtHemxi64d7EjivrAdM5pP3NxAwa8F G1JcOnkIWoQgH1bDrcxT/gPW+D0DHw3PzenkbpukF3NQ0jAOwt/Jz0vV4Vo1q1CLT4y0 l625uN59mRSb0SGYmmTG/YJ/t1IvtvoG7SGrRwAt/wAY/R+GCXoJ6lEg6R5UEoPDfOzT 2Viw== X-Gm-Message-State: AOAM5309bTH2o+5vo65PLkWw/yjyarnP0GYLzQGuMKJHezuDnE3dQn91 cwHz1tEmorMhl5aUuQJegECF2ydVXbM0wHGMryWuVB4kModYxUAgX408YoK+W0g0hA7A0xYWGS8 RCC0tll89wj2Fv6TKK4aCKD8YIN7dCCmE2b7XxB/+96hpyEb6kNyiCPiprF8hcRCbke9Xt6+sGK vBNOg= X-Google-Smtp-Source: ABdhPJxftsIm+me+NnjjNbOkKR0FFz0V57xjRlkhS6actEKSZ8DE7VB6/cCUZhhIc3eqXlFjK2qK6Cb0mV6g X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:27c2:28ad:b3af:418a]) (user=irogers job=sendgmr) by 2002:a05:6214:2a8a:: with SMTP id jr10mr7945292qvb.50.1623462309547; Fri, 11 Jun 2021 18:45:09 -0700 (PDT) Date: Fri, 11 Jun 2021 18:45:01 -0700 In-Reply-To: <20210612014501.890593-1-irogers@google.com> Message-Id: <20210612014501.890593-3-irogers@google.com> Mime-Version: 1.0 References: <20210612014501.890593-1-irogers@google.com> X-Mailer: git-send-email 2.32.0.272.g935e593368-goog Subject: [PATCH 2/2] libtraceevent: Changed angled brackets to double quotes. From: Ian Rogers To: linux-trace-devel@vger.kernel.org, Tzvetomir Stoyanov , Steven Rostedt , Claire Jensen Cc: Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org From: Claire Jensen Signed-off-by: Claire Jensen Signed-off-by: Ian Rogers --- 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, ...);