From mboxrd@z Thu Jan 1 00:00:00 1970 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=-0.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, HTML_MESSAGE,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 5569AC43603 for ; Wed, 4 Dec 2019 06:49:07 +0000 (UTC) Received: from isis.lip6.fr (isis.lip6.fr [132.227.60.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6591A20661 for ; Wed, 4 Dec 2019 06:48:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6591A20661 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=inria.fr Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=cocci-bounces@systeme.lip6.fr Received: from systeme.lip6.fr (systeme.lip6.fr [132.227.104.7]) by isis.lip6.fr (8.15.2/8.15.2) with ESMTP id xB46lkLo022124; Wed, 4 Dec 2019 07:47:46 +0100 (CET) Received: from systeme.lip6.fr (systeme.lip6.fr [127.0.0.1]) by systeme.lip6.fr (Postfix) with ESMTP id 31C2877D7; Wed, 4 Dec 2019 07:47:46 +0100 (CET) Received: from isis.lip6.fr (isis.lip6.fr [132.227.60.2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by systeme.lip6.fr (Postfix) with ESMTPS id A60A77708 for ; Wed, 4 Dec 2019 07:47:44 +0100 (CET) Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by isis.lip6.fr (8.15.2/8.15.2) with ESMTP id xB46lhuO013414 for ; Wed, 4 Dec 2019 07:47:43 +0100 (CET) X-IronPort-AV: E=Sophos;i="5.69,276,1571695200"; d="scan'208,217";a="417586219" X-MGA-submission: =?us-ascii?q?MDFZUn4RnCCft3xaCQV3XSEbDyuIklAKZZhHUl?= =?us-ascii?q?hV9zJ6DkVm82xkTotITnytbqVfmXZ/ZvG6fC3yFx06dkuYJ4/GomXq+7?= =?us-ascii?q?UWUXZeYXdJkQoDbwu3C97yJMPN8JcMXRRfrk0STnvwR08QRtI1H5O0jY?= =?us-ascii?q?cdqw70yEYofLGA33iLWaRA+A=3D=3D?= Received: from zcs-store9.inria.fr ([128.93.142.36]) by mail2-relais-roc.national.inria.fr with ESMTP; 04 Dec 2019 07:47:43 +0100 Date: Wed, 4 Dec 2019 07:47:43 +0100 (CET) From: Julia Lawall To: Strace Labs Message-ID: <1624931283.11188831.1575442063589.JavaMail.zimbra@inria.fr> In-Reply-To: References: <0c03f84d-a05b-2811-96aa-6f82541fb8a3@web.de> <1865799483.10870980.1575350298758.JavaMail.zimbra@inria.fr> MIME-Version: 1.0 X-Originating-IP: [202.161.33.40] X-Mailer: Zimbra 8.7.11_GA_3800 (ZimbraWebClient - FF70 (Linux)/8.7.11_GA_3800) Thread-Topic: Changing format string usage with SmPL? Thread-Index: 75yuBvJhUIXp1YzZ9OGJI38KC6y1RQ== X-Greylist: Sender IP whitelisted, Sender e-mail whitelisted, not delayed by milter-greylist-4.4.3 (isis.lip6.fr [132.227.60.2]); Wed, 04 Dec 2019 07:47:46 +0100 (CET) X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.4.3 (isis.lip6.fr [132.227.60.2]); Wed, 04 Dec 2019 07:47:43 +0100 (CET) X-Scanned-By: MIMEDefang 2.78 on 132.227.60.2 X-Scanned-By: MIMEDefang 2.78 on 132.227.60.2 Cc: cocci Subject: Re: [Cocci] Changing format string usage with SmPL? X-BeenThere: cocci@systeme.lip6.fr X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: multipart/mixed; boundary="===============0225182260==" Sender: cocci-bounces@systeme.lip6.fr Errors-To: cocci-bounces@systeme.lip6.fr --===============0225182260== Content-Type: multipart/alternative; boundary="=_2ec7c5fa-703b-471e-86e6-aae00c4996de" --=_2ec7c5fa-703b-471e-86e6-aae00c4996de Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable > De: "Strace Labs" > =C0: "Julia Lawall" > Cc: "cocci" > Envoy=E9: Mercredi 4 D=E9cembre 2019 01:28:22 > Objet: Re: [Cocci] Changing format string usage with SmPL? > Unfortunately, it doesn't work. But, I am working on some solutions using > Python. > therefore, once we have something like: > ... > @r1@ > format list fl; > identifier fn; > expression list e; > position p; > @@ > fn("%@fl@", e@p) > .... > Then, I could handle the format list using make_expr() as well. But, Is i= t > possible to rename/handle the expression list? Could you fix up the expression list first? Then you can write a rule like= =20 char[] s;=20 fn(s, ...,=20 - oldcode=20 + newcode=20 ,...)=20 julia=20 > On Tue, Dec 3, 2019 at 3:18 AM Julia Lawall < [ mailto:julia.lawall@inria= .fr | > julia.lawall@inria.fr ] > wrote: >>> De: "Strace Labs" < [ mailto:stracelabs@gmail.com | stracelabs@gmail.co= m ] > >>> =C0: "Markus Elfring" < [ mailto:Markus.Elfring@web.de | Markus.Elfring= @web.de ] > >>> Cc: "Julia Lawall" < [ mailto:julia.lawall@inria.fr | julia.lawall@inri= a.fr ] >, >>> [ mailto:cocci@systeme.lip6.fr | cocci@systeme.lip6.fr ] >>> Envoy=E9: Mardi 3 D=E9cembre 2019 11:30:14 >>> Objet: Re: [Cocci] Changing format string usage with SmPL? >>> On Sun, Dec 1, 2019 at 6:00 AM Markus Elfring < [ mailto:Markus.Elfring= @web.de | >>> Markus.Elfring@web.de ] > wrote: >>>>> Basically, I intend to replace alls "%s" called with "mydata->name" b= y "%m" with >>>> > "mydata" or "&mydata" >>>> How far would you get the desired source code transformation based on >>>> software extensions around a search pattern like the following. >>>> .......... >>>> Which algorithm will become sufficient for your data processing needs >>>> around the usage of functions with variadic arguments because of forma= t strings? >>> Actually, I really didn't get why you're asking about that. because we = are >>> talking about X and you're asking for Y. but, either way. that is not t= he >>> point. the point is because I am studying about the Coccinelle and I am= just >>> trying to figure out if the tool could detect "%s" called with "mydata-= >name" >>> and then replace by "%m" and remove the "->name" >>> e.g: Once if we have: >>> int foo() { >>> int id; >>> struct mydata h1, *h2, s1, *s2; >>> char *city =3D "Hello"; >>> my_printf("%s", s2->name); >>> my_printf("hi hi %s gggg", [ http://h1.name/ | h1.name ] ); >>> my_printf("1234 %d %s @ %d %s | %s -> city=3D%s", id, [ http://s1.name/= | s1.name >>> ] , 12, (*h2).name , h2->name , city); >>> my_printf("aaaa %s hhhhh", h2->name); >>> my_printf("%s", city); >>> } >>> Then, replace by: >>> int foo() { >>> int id; >>> struct mydata h1, *h2, s1, *s2; >>> char *city =3D "Hello"; >>> my_printf("%m", s2); >>> my_printf("hi hi %s gggg", &h1); >>> my_printf("1234 %d %m @ %d %m | %m -> city=3D%s", id, [ http://s1.name/= | s1.name >>> ] , 12, (*h2).name , h2->name , city); >>> my_printf("aaaa %s hhhhh", h2); >>> my_printf("%s", city); >>> } >>> But, I've read again the other samples and the documentation. therefore= , I >>> didn't figure out how it should be. btw, thank you Julia for the sugges= tion >>> performing the Ocalm/make_expr/replace . (Due to something wrong with t= he >>> Coccinelle distributed by Brew/Osx. I just rewrote your sample using Py= thon and >>> the result was the same. But, I can't just replace all "%s" by "%m". As= I said, >>> it should be only if the "%s" was declared to use "mydata->name". >>> so, I still fighting yet. thanks in Advance. >> OK, if you may have more than one argument to your print, then you can f= ind the >> offset using an expression list metavariable: >> @r@ >> expression list[n] between; >> @@ >> print(s,between,h2->name,...) >> Then you can use r.n in your python rule to figure out where is the %s t= o >> change. Unfortunately, this will not work well if there are multiple nam= e >> references in the argument list. Because you will be trying to change th= e >> format string in multiple ways, eg once where between has length 2 and o= nce >> where between has length 4. Substantial hacks would be required to deal = with >> this. >> It would be nice if you could do >> @r@ >> expression list[bn] between; >> expression list[an] after; >> position p; >> @@ >> print@p(s,between,name,after) >> @@ >> format list[ [ http://r.bn/ | r.bn ] ] f1; >> format list[ [ http://r.an/ | r.an ] ] f2; >> position r.p; >> @@ >> print@p( >> - "%@f1@%s%@f2@" >> + "%@f1@%m%@f2@" >> , l) >> I don't know if that would work, though. >> julia >>>> Regards, >>>> Markus --=_2ec7c5fa-703b-471e-86e6-aae00c4996de Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable



De: "Strace Labs" <st= racelabs@gmail.com>
=C0: "Julia Lawall" <julia.lawall@inria= .fr>
Cc: "cocci" <cocci@systeme.lip6.fr>
Envoy=E9:= Mercredi 4 D=E9cembre 2019 01:28:22
Objet: Re: [Cocci] Chang= ing format string usage with SmPL?
Unfortunately, it doesn't work. But,= I am working on some solutions using Python. 
<= br>
therefore, once we have something like:

...
@r1@
format list fl;
identifier fn;
expression list e;
p= osition p;
@@

fn("%@fl@", e@p)
....

T= hen, I could handle the format list using make_expr() as well. But, Is it possible to rename/handle the expression lis= t?

Could you fix up the exp= ression list first?  Then you can write a rule like

char[] s;

fn(s, ...,
- oldcode
+ newcode
   ,...)

julia







On Tue, Dec 3, 2019 at 3:18 AM Juli= a Lawall <jul= ia.lawall@inria.fr> wrote:

<= div>
= De: "Strace Labs" <stracelabs@gmail.com>
=C0: "Markus Elfring" &l= t;Markus.Elfring= @web.de>
Cc: "Julia Lawall" <julia.lawall@inria.fr>, cocci@systeme.lip6.frEnvoy=E9: Mardi 3 D=E9cembre 2019 11:30:14
Objet: Re: [C= occi] Changing format string usage with SmPL?
On Sun, Dec 1, 2019 at 6:00 AM Markus Elfring &= lt;Markus.Elfrin= g@web.de> wrote:
> Basically, I intend to replace alls= "%s" called with "mydata->name" by "%m" with "mydata" or "&mydata"<= br>
How far would you get the desired source code transformation based on
software extensions around a search pattern like the following.
........= ..
Which algorithm will become sufficient for your data processing needs
around the usage of functions with variadic arguments because of format str= ings?


Actually, I really didn't get why you're= asking about that. because we are talking about X and you're asking for Y.= but, either way. that is not the point. the point is because I am studying= about the Coccinelle and I am just trying to figure out if the tool could = detect "%s" called with "mydata->name" and then replace by "%m" and remo= ve the "->name"

e.g: Once if we have:

int fo= o() {
  int id;
  struct mydata h1, *h2, s1, *s2;
 = char *city =3D "Hello";
  my_printf("%s", s2->name);
  = my_printf("hi hi %s gggg", h1.= name);
  my_printf("1234 %d %s @ %d %s | = %s -> city=3D%s", id, s1.name, 12, (*h2).name, h2->name, city);
&nb= sp; my_printf("aaaa %s hhhhh", h2->name);
  my_printf("%s", city= );
}

Then, replace by:

int f= oo() {
  int id;
  struct mydata h1, *h2, s1, *s2;
 = ; char *city =3D "Hello";
my_printf("%m", s2);
my_printf("h= i hi %s gggg", &h1);
  my_printf("1234 %d %m @ = %d %m | %m -> city=3D%s", id, s1.name, 12, (*h2).name, h2= ->name, city);
  my_printf("aaaa %s hhhhh", h2);
&= nbsp; my_printf("%s", city);
}

But, I've = read again the other samples and the documentation. therefore, I didn't fig= ure out how it should be. btw, thank you Julia for the suggestion performin= g the Ocalm/make_expr/replace. (Due to something wrong with the Cocc= inelle distributed by Brew/Osx. I just rewrote your sample using Python and= the result was the same. But, I can't just replace all "%s" by "%m". As I = said, it should be only if the "%s" was declared to use "mydata->name".<= /div>
so, I still fighting yet. thanks in Advance.
OK, if you may have more than one argument to your print= , then you can find the offset using an expression list metavariable:

@r@
expression list[n] between;
@@=

print(s,between,h2->name,...)

Then = you can use r.n in your python rule to figure out where is the %s to change= .  Unfortunately, this will not work well if there are multiple name r= eferences in the argument list.  Because you will be trying to change = the format string in multiple ways, eg once where between has length 2 and = once where between has length 4.  Substantial hacks would be required = to deal with this.

It would be nice if you could do

@r@
expression list[bn] between;
e= xpression list[an] after;
position p;
@@
print@p(s,between,name,after)

@@
fo= rmat list[r.bn] f1;
=
format list[r.an] f2;
position r.p;
@@
print@p(
-    "%@f1@%s%@f2@"
+   "%@f1@%m%@f= 2@"
, l)

I don't know if that would work, t= hough.

julia

Regards,
Markus

--=_2ec7c5fa-703b-471e-86e6-aae00c4996de-- --===============0225182260== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci --===============0225182260==--