From patchwork Sat Feb 9 13:25:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zephaniah E. Loss-Cutler-Hull" X-Patchwork-Id: 10804465 X-Patchwork-Delegate: lenb@kernel.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4A40D746 for ; Sat, 9 Feb 2019 13:25:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2EF9C2A3DE for ; Sat, 9 Feb 2019 13:25:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 217B82B1E8; Sat, 9 Feb 2019 13:25:53 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,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 BE3582A3DE for ; Sat, 9 Feb 2019 13:25:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726724AbfBINZw (ORCPT ); Sat, 9 Feb 2019 08:25:52 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:34129 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726722AbfBINZv (ORCPT ); Sat, 9 Feb 2019 08:25:51 -0500 Received: by mail-pg1-f195.google.com with SMTP id d9so2829428pgl.1 for ; Sat, 09 Feb 2019 05:25:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:cc:from:subject:message-id:date:user-agent:mime-version :content-language:content-transfer-encoding; bh=sT6DTRA4iDtBhBQ/LcWa678/51gkDsFxEUWTc441T+o=; b=QhiveI48aXQ/QKrA0PM0CwQ5lvBQY4+2xfVlJz8AkW2E4EQaVyn6Vzk0U/kMVI4NcB ZPVXlSZRwh0DugWHmZcfECBYw2qZLcSRMsniTS2sDy//4UpUOLdzcR5MdcZAF9mCZDPf acdgQiYZN7AFoCTLYzOUrUp7OP2GnYxXThT3vrJLZt7g8tl62lWOPV+NhySI3uQux2gL xPWbraHINXlQP2H2SErqtANtkgr4rv8aJrJxrZ5ALKvcBjREsM+DwFaD+0JbICeWpUCd znTP+RDIokJEBBFW9Pw5IQQWEggk0wZ0AVFl2JENRGwYgHT2iTFZNfCmB22cVEhuNaIC wkVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version:content-language:content-transfer-encoding; bh=sT6DTRA4iDtBhBQ/LcWa678/51gkDsFxEUWTc441T+o=; b=qPHCspZTZnDGOtBPOEZvV/ZpqKfSe8YYOrS06zXWAlKJpnWy1J+QfB4E69KxsWImYf KEwo9vxkPhMHAKkLoEnnV2oYMS4QzsY7M4rUzycb5RLv1YWC/i1aB4Kc+CpVwux6yacl rRgE79BqfATsUglvTiHHeVx6MexNmpb/WiuKdr8mVbc7XrEP3Ivb6JxojIVTJV1XW+4/ 2SJtNahCjoJCEdBpf8MYHo4BHSnImKaFDA/3sFriArWE4nTUsV57aNs8H5i+a8VR3UCV uxDOpQlVtxZBhcOsm2U4+QXqvf/S2emLlyYKyTm/YsRbaXhsjZtWKtkVagzbyNCd5hbu xq6Q== X-Gm-Message-State: AHQUAubuSkbgeOwu4ZQcBRBAA2Gl9QJq7e0wRDZ6ZlvEiAUmfCNo7yUS jWOMC/4Rd9a58xeL5aGjMm0= X-Google-Smtp-Source: AHgI3IahuMQXomX3at3O8kjgqPJmbrLboR2WWW1I5F/yP5DS1MZnfTgqrn0akwTGQFtSOJOaaONT7Q== X-Received: by 2002:a62:109b:: with SMTP id 27mr27255432pfq.227.1549718750313; Sat, 09 Feb 2019 05:25:50 -0800 (PST) Received: from [10.0.5.151] (24-113-236-136.wavecable.com. [24.113.236.136]) by smtp.gmail.com with ESMTPSA id s12sm782202pfm.120.2019.02.09.05.25.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 09 Feb 2019 05:25:49 -0800 (PST) To: linux-pm@vger.kernel.org Cc: Len Brown From: "Zephaniah E. Loss-Cutler-Hull" Subject: [PATCH] Fix argument parsing in x86_energy_perf_policy. Message-ID: <17f38ecc-e3ed-d7fb-42d1-bdb87a393aa6@gmail.com> Date: Sat, 9 Feb 2019 05:25:48 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 Content-Language: en-US Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The -w argument in x86_energy_perf_policy currently triggers an unconditional segfault. This is because the argument string reads: "+a:c:dD:E:e:f:m:M:rt:u:vw" and yet the argument handler expects an argument. When parse_optarg_string is called with a null argument, we then proceed to crash in strncmp, not horribly friendly. The man page describes -w as taking an argument, the long form (--hwp-window) is correctly marked as taking a required argument, and the code expects it. As such, this patch simply marks the short form (-w) as requiring an argument. Signed-off-by: Zephaniah E. Loss-Cutler-Hull diff --git a/tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c b/tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c index 65bbe627a425..3d442361d29c 100644 --- a/tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c +++ b/tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c @@ -546,7 +546,7 @@ void cmdline(int argc, char **argv) progname = argv[0]; - while ((opt = getopt_long_only(argc, argv, "+a:c:dD:E:e:f:m:M:rt:u:vw", + while ((opt = getopt_long_only(argc, argv, "+a:c:dD:E:e:f:m:M:rt:u:vw:", long_options, &option_index)) != -1) { switch (opt) { case 'a':