[procps] Re: [BUG] Commit 81df8e2 allows only one key=value arg

  • From: Sami Kerola <kerolasa@xxxxxx>
  • To: procps@xxxxxxxxxxxxx, Sven Ulland <sveniu@xxxxxxxxx>
  • Date: Wed, 7 Mar 2012 12:57:16 +0100

On Wed, Mar 7, 2012 at 00:33, Jim Warner <james.warner@xxxxxxxxxxx> wrote:
> On Mar 6, 2012, at 9:50 AM, Sami Kerola wrote:
>> Hi Sven & Craig,
>>
>> Thanks for regressions report. This could be release 3.3.3 blocker,
>> and I am keen to it is. Without reviewing the source I cannot say from
>> top of my head how easy or time consuming fixing might be. Let's hope
>> it's trivial.
>
> Hi Sami, Sven & Craig,
>
> In an effort to *try* to help out, I offer the diff below.
>
> It seems to accomplish the desired goal, but Sami should be the judge.

Hi Jim et.al.

Jim, thank you for fix, to my view it works perfectly. Craig, find
from attachment a patch in git am format which should be applied
before next release.

-- 
   Sami Kerola
   http://www.iki.fi/kerolasa/
From 31da40f037db954bbb1fa4f2a6e5026172c9541e Mon Sep 17 00:00:00 2001
From: Jim Warner <james.warner@xxxxxxxxxxx>
Date: Wed, 7 Mar 2012 12:49:09 +0100
Subject: [PATCH] sysctl: fix argument parsing regression

Any key=value pair following the first one are dropped after
commit 81df8e26300b35968e3702decc02e9413d5389fc, due to changing
from the while loop to using getopt.

Broken behavior:
  sysctl net.ipv6.conf.tun0.optimistic_dad net.ipv6.conf.tun0.mc_forwarding
  net.ipv6.conf.tun0.optimistic_dad = 0

Good behavior:
  sysctl net.ipv6.conf.tun0.optimistic_dad net.ipv6.conf.tun0.mc_forwarding
  net.ipv6.conf.tun0.optimistic_dad = 0
  net.ipv6.conf.tun0.mc_forwarding = 0

Reference: 
//www.freelists.org/post/procps/BUG-Commit-81df8e2-allows-only-one-keyvalue-arg
Reported-By: Sven Ulland <sveniu@xxxxxxxxx>
Signed-off-by: Jim Warner <james.warner@xxxxxxxxxxx>
Signed-off-by: Sami Kerola <kerolasa@xxxxxx>
---
 sysctl.c |   15 +++++++++------
 1 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/sysctl.c b/sysctl.c
index a2fa211..e361970 100644
--- a/sysctl.c
+++ b/sysctl.c
@@ -687,7 +687,7 @@ int main(int argc, char *argv[])
 
        while ((c =
                getopt_long(argc, argv, "bneNwfp::qoxaAXr:Vdh", longopts,
-                           NULL)) != -1)
+                           NULL)) != -1) {
                switch (c) {
                case 'b':
                        /* This is "binary" format, which means more for BSD. */
@@ -748,6 +748,8 @@ int main(int argc, char *argv[])
                default:
                        Usage(stderr);
                }
+       }
+
        if (DisplayAllOpt)
                return DisplayAll(PROC_PATH);
        if (preloadfileOpt)
@@ -765,10 +767,11 @@ int main(int argc, char *argv[])
                                      "Try `%s --help' for more information."),
                      program_invocation_short_name);
 
-       if (WriteMode || index(*argv, '='))
-               ReturnCode = WriteSetting(*argv);
-       else
-               ReturnCode = ReadSetting(*argv);
-
+       for ( ; *argv; argv++) {
+               if (WriteMode || index(*argv, '='))
+                       ReturnCode += WriteSetting(*argv);
+               else
+                       ReturnCode += ReadSetting(*argv);
+       }
        return ReturnCode;
 }
-- 
1.7.5.4

Other related posts: