public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
From: Chen Yu <yu.c.chen@intel.com>
To: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
	Len Brown <lenb@kernel.org>,
	Robert Moore <robert.moore@intel.com>,
	<linux-acpi@vger.kernel.org>,
	<acpica-devel@lists.linuxfoundation.org>,
	<linux-kernel@vger.kernel.org>,
	Hariganesh Govindarajulu <hariganesh.govindarajulu@intel.com>
Subject: Re: [PATCH] ACPI: tools: pfrut: Check if the input of level and type is in the right numeric range
Date: Wed, 8 Mar 2023 12:20:24 +0800	[thread overview]
Message-ID: <ZAgNCCUMjP3W35qd@chenyu5-mobl1> (raw)
In-Reply-To: <CAJZ5v0h8Z8_zb_seSfsFsgWksG6N41jFcuTycrEicJYJOG1yLQ@mail.gmail.com>

Hi Rafael,
thanks for the review,
On 2023-03-07 at 12:38:02 +0100, Rafael J. Wysocki wrote:
> On Tue, Mar 7, 2023 at 4:46 AM Chen Yu <yu.c.chen@intel.com> wrote:
> >
> > The user can provide arbitrary non-numeic value to level and type, which
> > brings unexpected behavior:
> 
> So I guess the expected behavior would be to throw an error?
> 
Yes.
> >  pfrut -h
> > usage: pfrut [OPTIONS]
> > code injection:
> > -l, --load
> > -s, --stage
> > -a, --activate
> > -u, --update [stage and activate]
> > -q, --query
> > -d, --revid
> > update telemetry:
> > -G, --getloginfo
> > -T, --type(0:execution, 1:history)
> > -L, --level(0, 1, 2, 4)
> > -R, --read
> > -D, --revid log
> >
> >  pfrut -T A
> >  pfrut -G
> > log_level:0
> > log_type:0
> > log_revid:2
> > max_data_size:65536
> > chunk1_size:0
> > chunk2_size:1530
> > rollover_cnt:0
> > reset_cnt:17
> >
> > Fix this by restricting the input is in the expected range.
> >
> > Reported-by: Hariganesh Govindarajulu <hariganesh.govindarajulu@intel.com>
> > Signed-off-by: Chen Yu <yu.c.chen@intel.com>
> > ---
> >  tools/power/acpi/tools/pfrut/pfrut.c | 33 ++++++++++++++++++++++++++++
> >  1 file changed, 33 insertions(+)
> >
> > diff --git a/tools/power/acpi/tools/pfrut/pfrut.c b/tools/power/acpi/tools/pfrut/pfrut.c
> > index 52aa0351533c..ed672efef83b 100644
> > --- a/tools/power/acpi/tools/pfrut/pfrut.c
> > +++ b/tools/power/acpi/tools/pfrut/pfrut.c
> > @@ -22,6 +22,7 @@
> >  #include <sys/ioctl.h>
> >  #include <sys/mman.h>
> >  #include <uuid/uuid.h>
> > +#include <ctype.h>
> >  #include PFRUT_HEADER
> >
> >  char *capsule_name;
> > @@ -77,6 +78,18 @@ static void help(void)
> >                 progname);
> >  }
> >
> > +static int is_digit_input(char *str)
> > +{
> > +       char *scan;
> > +
> > +       for (scan = str; *scan != '\0'; scan++) {
> > +               if (!isdigit(*scan))
> > +                       return 0;
> > +       }
> > +
> > +       return 1;
> > +}
> > +
> >  char *option_string = "l:sauqd:GT:L:RD:h";
> >  static struct option long_options[] = {
> >         {"load", required_argument, 0, 'l'},
> > @@ -125,11 +138,31 @@ static void parse_options(int argc, char **argv)
> >                         log_getinfo = 1;
> >                         break;
> >                 case 'T':
> > +                       if (!is_digit_input(optarg)) {
> > +                               printf("Please provide numeric value for type (0:execution, 1:history) - Exiting.\n");
> > +                               exit(1);
> > +                       }
> > +
> 
> Wouldn't using strtol() instead of atoi() work?
> 
Yes, strtol() would be simpler:
c = strtol(optarg, &endptr, 0)
if (*endptr)
	exit(1);
I'll change it in next version.

thanks,
Chenyu

      reply	other threads:[~2023-03-08  4:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-07 11:41 [PATCH] ACPI: tools: pfrut: Check if the input of level and type is in the right numeric range Chen Yu
2023-03-07 11:38 ` Rafael J. Wysocki
2023-03-08  4:20   ` Chen Yu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZAgNCCUMjP3W35qd@chenyu5-mobl1 \
    --to=yu.c.chen@intel.com \
    --cc=acpica-devel@lists.linuxfoundation.org \
    --cc=hariganesh.govindarajulu@intel.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafael.j.wysocki@intel.com \
    --cc=rafael@kernel.org \
    --cc=robert.moore@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox