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.3 required=3.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 EC551C432C0 for ; Tue, 3 Dec 2019 17:29:18 +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 1E8D92073C for ; Tue, 3 Dec 2019 17:29:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="knqS1NLY" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1E8D92073C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com 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 xB3HT1BV023649; Tue, 3 Dec 2019 18:29:02 +0100 (CET) Received: from systeme.lip6.fr (systeme.lip6.fr [127.0.0.1]) by systeme.lip6.fr (Postfix) with ESMTP id AE20F77D7; Tue, 3 Dec 2019 18:29:01 +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 3551C4386 for ; Tue, 3 Dec 2019 18:29:00 +0100 (CET) Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20:0:0:0:42d] (may be forged)) by isis.lip6.fr (8.15.2/8.15.2) with ESMTP id xB3HSxGQ013992 for ; Tue, 3 Dec 2019 18:28:59 +0100 (CET) Received: by mail-wr1-x42d.google.com with SMTP id w15so4734672wru.4 for ; Tue, 03 Dec 2019 09:28:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=GpqYcNI46CBJx+2Kv0Sq5xfRzTSQSo8gHFOn1y7GqAM=; b=knqS1NLYUpak86PYSQilX5H7a1nzhOwIPeAD4wptJ2e4xES2w9Q4HmyY+ldRieCad/ 1GdLaiA+JNDgEDaFEIG5/lBPT0Y80ipFdZ3cNG0YulhEJUwuH16TnHfgBcrQ58WDanGx r/Qk8I8hX9FJxi1ZDChmRrdt6rv8YHcjAgldF5xhkGdnan+nOBp6dMEciDqDw2+pbRTG MzJUznCZKwpZB/mmP7tIPTwFLXaAgKqaybAlGQPFpCeJuRiOYpeO+3tFi95vuwJW1LnU LoirpMsstZeYgn+kO+9pY06Q/DXaGHuXw50Thkdr2ndRKYpwARbs4T3fEolkrQiccb27 43uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=GpqYcNI46CBJx+2Kv0Sq5xfRzTSQSo8gHFOn1y7GqAM=; b=MAR/PGYfWZgtwR4ZruwXecgjKB7YxIF6FhGXzmJjoR2JbimtAPGNOqgKhPYSG3aWUJ 8ApyAC6K7F3Ui7iix7nlm6uW55eutG34NEMqC9K+x9QXbwe/BgFy8jdnJ5d10oOKB0jG TeSlz06qDK1+O+ZvGTuoRGRJppLOVI7psCVm3Aqbw9AbYCFPIHyPO2DnRzkHGNiOc98O kfCcfHaiaJC2P67cTWNot0bBe3K51YNsg/eukjEadz+yz1dLxdR9SeCLDOWXCBY/6cC9 xMS+mE8ZYGj9GUJTZFOjCl5z+deXQXpFXcZrrH8Epj7PyHr4G8o/iCb1NYwlryMQ05Yb w5VQ== X-Gm-Message-State: APjAAAXJozrcLBjQiEhqSD8//jKL+H9SDtXcBp7oap1YDGKS9oghbLbm 2N5ZeEFGEdsfk4qr0uo7/jCO+5Vvj3DPx5fMUAk= X-Google-Smtp-Source: APXvYqxeZfMCfj2qPtNI82UFuTSjUVcGnKcI6gwgy7zQjWx6ReoBgmyENPpttSFFe8IJUbn3WuNK+WS8eBD1mjcQDVA= X-Received: by 2002:a05:6000:1241:: with SMTP id j1mr6885299wrx.26.1575394138819; Tue, 03 Dec 2019 09:28:58 -0800 (PST) MIME-Version: 1.0 References: <02fa7455-e76e-7d7d-0d64-41b2803a8025@web.de> <0c03f84d-a05b-2811-96aa-6f82541fb8a3@web.de> <1865799483.10870980.1575350298758.JavaMail.zimbra@inria.fr> In-Reply-To: <1865799483.10870980.1575350298758.JavaMail.zimbra@inria.fr> From: Strace Labs Date: Tue, 3 Dec 2019 15:28:22 -0200 Message-ID: To: Julia Lawall X-Greylist: Sender IP whitelisted, Sender e-mail whitelisted, not delayed by milter-greylist-4.4.3 (isis.lip6.fr [132.227.60.2]); Tue, 03 Dec 2019 18:29:02 +0100 (CET) X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.4.3 (isis.lip6.fr [IPv6:2001:660:3302:283c:0:0:0:2]); Tue, 03 Dec 2019 18:28:59 +0100 (CET) X-Scanned-By: MIMEDefang 2.78 on 132.227.60.2 X-Scanned-By: MIMEDefang 2.78 Cc: cocci@systeme.lip6.fr 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="===============0896038969==" Sender: cocci-bounces@systeme.lip6.fr Errors-To: cocci-bounces@systeme.lip6.fr --===============0896038969== Content-Type: multipart/alternative; boundary="0000000000000693800598d008a0" --0000000000000693800598d008a0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 it possible to rename/handle the *expression list?* On Tue, Dec 3, 2019 at 3:18 AM Julia Lawall wrote: > ------------------------------ > > *De: *"Strace Labs" > *=C3=80: *"Markus Elfring" > *Cc: *"Julia Lawall" , cocci@systeme.lip6.fr > *Envoy=C3=A9: *Mardi 3 D=C3=A9cembre 2019 11:30:14 > *Objet: *Re: [Cocci] Changing format string usage with SmPL? > > On Sun, Dec 1, 2019 at 6:00 AM Markus Elfring > wrote: > >> > Basically, I intend to replace alls "%s" called with "mydata->name" by >> "%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 format >> strings? >> >> > Actually, I really didn't get why you're asking about that. because we ar= e > 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 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", h1.name); > my_printf("1234 %d *%s* @ %d *%s* | *%s* -> city=3D%s", id, *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, *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 suggesti= on > performing the *Ocalm/make_expr/replace*. (Due to something wrong with > the Coccinelle 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". > > 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 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 on= ce > 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[r.bn] f1; > format list[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 >> > > --0000000000000693800598d008a0 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Unfortunately, it doesn't work. But, = I am working on some solutions using Python.=C2=A0
therefore, once we have something like:

...
@r1@
format list fl;
identifier fn;
expression li= st e;
position p;
@@

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

Then, I could handle the format list= =C2=A0using=C2=A0make_expr()=C2=A0as well. But, Is it possible to re= name/handle the expression list?


On Tue, Dec 3, 2019 = at 3:18 AM Julia Lawall <julia.= lawall@inria.fr> wrote:

= De: "Strace Labs" <stracelabs@gmail.com>
=C3=80: "Mar= kus Elfring" <Markus.Elfring@web.de>
Cc: "Julia Lawall" = <julia.lawall= @inria.fr>, cocci@systeme.lip6.fr
Envoy=C3=A9: Mardi 3 D=C3=A9cembre 2= 019 11:30:14
Objet: Re: [Cocci] Changing format string usage with= SmPL?
On Sun, Dec= 1, 2019 at 6:00 AM Markus Elfring <Markus.Elfring@web.de> wrote:
>= Basically, I intend to replace alls "%s" called with "mydat= a->name" by "%m" with "mydata" or "&my= data"

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 yo= u're asking about that. because we are talking about X and you're a= sking 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" a= nd then replace by "%m" and remove the "->name"
e.g: Once if we have:

int foo() {
=C2=A0 int id;=
=C2=A0 struct mydata h1, *h2, s1, *s2;
=C2=A0 char *city =3D "H= ello";
=C2=A0 my_printf("%s", s2->name);
=C2=A0 my_= printf("hi hi %s gggg", h1.name);
=C2=A0 my_printf("1234 %d %s @ %d %s=C2=A0| %s -> city=3D%s", id, s1.name, 12, (*h2).name, h2->name, city);
=C2=A0 my_printf("aaaa %s hhhhh", h2->name);
= =C2=A0 my_printf("%s", city);
}

Then,= replace by:

int foo() {
=C2=A0 int id;
=C2=A0 str= uct mydata h1, *h2, s1, *s2;
=C2=A0 char *city =3D "Hello";my_printf("%m", s2);
my_printf("hi hi %s gggg&= quot;, &h1);
=C2=A0 my_printf("1234 %d %m=C2=A0@ %d = %m=C2=A0| %m=C2=A0-> city=3D%s", id, s1.name, 12, (*h2).name, = h2->name, city);
=C2=A0 my_printf("aaaa %s hhhhh", h= 2);
=C2=A0 my_printf("%s", city);
}

But, I've read again the other samples and the documentatio= n. therefore, I didn't figure out how it should be. btw, thank you Juli= a for the suggestion performing the Ocalm/make_expr/replace. (Due to= something wrong with the Coccinelle distributed by Brew/Osx. I just rewrot= e your sample using Python and the result was the same. But, I can't ju= st replace all "%s" by "%m". As I said, it should be on= ly 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 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 figu= re out where is the %s to change.=C2=A0 Unfortunately, this will not work w= ell if there are multiple name references in the argument list.=C2=A0 Becau= se 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.=C2=A0 Subs= tantial hacks would be required to deal with this.

=
It would be nice if you could do

@r@
<= /div>
expression list[bn] between;
expression list[an] af= ter;
position p;
@@
print@p(s,bet= ween,name,after)

@@
format list[= r.bn] f1;
forma= t list[r.an] f2;
position r.p;
@@
print@p(
-=C2=A0= =C2=A0=C2=A0 "%@f1@%s%@f2@"
+=C2=A0=C2=A0 "%@f= 1@%m%@f2@"
, l)

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

julia

Regards,
Markus

--0000000000000693800598d008a0-- --===============0896038969== 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 --===============0896038969==--