[sheepdog] [PATCH v2] dog:fix dog command misinterpretation when characters are mixed in a -p option

Hitoshi Mitake mitake.hitoshi at gmail.com
Mon Apr 21 06:05:20 CEST 2014


On Mon, Apr 21, 2014 at 12:00 PM, Yuichi Bando
<bando.yuichi at lab.ntt.co.jp> wrote:
> This bug is reported in https://bugs.launchpad.net/sheepdog-project/+bug/1309301
> I added a check code if the port number (specified in -p option) is numeric or not.
>
> === Bug Description ===
> I found that dog command misinterprets when characters are mixed in a numeric option.
>
> Here's the example.
>
> $dog vdi list -p 7X000
>   Name Id Size Used Shared Creation time VDI id Copies Tag
> failed to connect to 127.0.0.1:7: Connection refused
> failed to connect to 127.0.0.1:7: Connection refused
>
> dog interpreted "7X000" as "7".
> I think that dog should output error message " Invalid port number '7X000' ".
>
> === After modified ===
> $dog vdi list -p 7X000
> Invalid port number '7X000'
>
> Thanks
> Yuichi Bando
>
> Signed-off-by: Yuichi Bando <bando.yuichi at lab.ntt.co.jp>
> ---
>  dog/dog.c |    3 ++-
>  1 files changed, 2 insertions(+), 1 deletions(-)
>
>  v2: fix style

Looks good to me.
Reviewed-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>

>
> diff --git a/dog/dog.c b/dog/dog.c
> index fbedd6d..7942b34 100644
> --- a/dog/dog.c
> +++ b/dog/dog.c
> @@ -467,7 +467,8 @@ int main(int argc, char **argv)
>                         break;
>                 case 'p':
>                         sdport = strtol(optarg, &p, 10);
> -                       if (optarg == p || sdport < 1 || sdport > UINT16_MAX) {
> +                       if (optarg == p || sdport < 1 || sdport > UINT16_MAX
> +                                       || !is_numeric(optarg)) {
>                                 sd_err("Invalid port number '%s'", optarg);
>                                 exit(EXIT_USAGE);
>                         }
> --
> 1.7.1
>
>
> --
> sheepdog mailing list
> sheepdog at lists.wpkg.org
> http://lists.wpkg.org/mailman/listinfo/sheepdog



More information about the sheepdog mailing list