[prev in list] [next in list] [prev in thread] [next in thread] 

List:       asterisk-dev
Subject:    Re: [asterisk-dev] [Code Review] Convert two classes of strncpy usage to ast_copy_string
From:       "opticron" <reviewboard () asterisk ! org>
Date:       2012-02-28 13:39:45
Message-ID: 20120228133945.6923.34644 () hotblack ! digium ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviewboard.asterisk.org/r/1732/#review5664
-----------------------------------------------------------


Based on conversation here, it looks like this is waiting for an updated pa=
tch that includes only a,b,sizeof(a) and a,b,sizeof(a)-1 and excludes utils=
.  I'd also recommend leaving out app_rpt since it's going away soon.

- opticron


On Feb. 10, 2012, 8:29 p.m., Terry Wilson wrote:
> =

> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviewboard.asterisk.org/r/1732/
> -----------------------------------------------------------
> =

> (Updated Feb. 10, 2012, 8:29 p.m.)
> =

> =

> Review request for Asterisk Developers.
> =

> =

> Summary
> -------
> =

> One of the janitor projects is to replace strncpy with ast_copy_string wh=
ere possible. As a brief example of using the coccinelle tool, I thought I'=
d post an example for using it. There are some cases of strncpy which where=
 ast_copy_string wouldn't be appropriate--sepcifically when it is used to c=
opy non-NULL terminated buffers (instead of memcpy, which should be used fo=
r that). Two cases that I think should be completely safe are where we have=
 something like strncpy(src, dst, ${something} - 1) and strncpy(src, dst, s=
izeof(src)) (which is a bug waiting to happen). =

> =

> Here is the coccinelle patch to do the translation:
> =

> strncpy.cocci
> @@
> expression a, b, c;
> @@
> =

> - strncpy(a, b, c - 1)
> + ast_copy_string(a, b, c)
> =

> @@
> expression a, b;
> @@
> =

> - strncpy(a, b, sizeof(a))
> + ast_copy_string(a, b, sizeof(a))
> =

> Coccinelle needs a little help with some of the macros in Asterisk--so fa=
r it looks like the ones in linkedlists.h and app.h give it the most troubl=
e. You can generate a macro file to use by doing:
> =

> spatch -extract_macros include/asterisk/linkedlists.h > /tmp/spatch.h
> spatch -extract_macros include/asterisk/app.h >> /tmp/spatch.h
> =

> I've found that doing all of the includes sometimes makes it miss stuff f=
or some reason...
> =

> Then to run the patch file on all the files in the asterisk directory:
> spatch -sp_file strncpy.cocci -preprocess -c -in_place -I include/ -local=
_includes -macro_file /tmp/spatch.h -smpl_spacing -dir .
> =

> You may have to fix some stuff up manually, but it goes a long way to mak=
ing things a lot easier. This is a simple example of how the channel opaqui=
fication is done. I'll write this all up on the Wiki, but am basically just=
 doing a quick brain dump before I leave for the night.
> =

> =

> Diffs
> -----
> =

>   /trunk/addons/chan_ooh323.c 354785 =

>   /trunk/addons/ooh323c/src/ooCalls.c 354785 =

>   /trunk/addons/ooh323c/src/ooCmdChannel.c 354785 =

>   /trunk/addons/ooh323c/src/ooh323ep.c 354785 =

>   /trunk/addons/ooh323c/src/ooq931.c 354785 =

>   /trunk/apps/app_rpt.c 354785 =

>   /trunk/channels/iax2-provision.c 354785 =

>   /trunk/pbx/dundi-parser.c 354785 =

>   /trunk/res/ael/ael_lex.c 354785 =

>   /trunk/res/snmp/agent.c 354785 =

>   /trunk/utils/ael_main.c 354785 =

>   /trunk/utils/astman.c 354785 =

>   /trunk/utils/db1-ast/hash/ndbm.c 354785 =

>   /trunk/utils/muted.c 354785 =

> =

> Diff: https://reviewboard.asterisk.org/r/1732/diff
> =

> =

> Testing
> -------
> =

> It compiles.
> =

> =

> Thanks,
> =

> Terry
> =

>


[Attachment #5 (text/html)]

<html>
 <body>
  <div style="font-family: Verdana, Arial, Helvetica, Sans-Serif;">
   <table bgcolor="#f9f3c9" width="100%" cellpadding="8" style="border: 1px #c9c399 \
solid;">  <tr>
     <td>
      This is an automatically generated e-mail. To reply, visit:
      <a href="https://reviewboard.asterisk.org/r/1732/">https://reviewboard.asterisk.org/r/1732/</a>
  </td>
    </tr>
   </table>
   <br />





 <pre style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: \
-pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">Based on conversation \
here, it looks like this is waiting for an updated patch that includes only \
a,b,sizeof(a) and a,b,sizeof(a)-1 and excludes utils.  I&#39;d also recommend leaving \
out app_rpt since it&#39;s going away soon.</pre>  <br />







<p>- opticron</p>


<br />
<p>On February 10th, 2012, 8:29 p.m., Terry Wilson wrote:</p>






<table bgcolor="#fefadf" width="100%" cellspacing="0" cellpadding="8" \
style="background-image: \
url('https://reviewboard.asterisk.org/media/rb/images/review_request_box_top_bg.png'); \
background-position: left top; background-repeat: repeat-x; border: 1px black \
solid;">  <tr>
  <td>

<div>Review request for Asterisk Developers.</div>
<div>By Terry Wilson.</div>


<p style="color: grey;"><i>Updated Feb. 10, 2012, 8:29 p.m.</i></p>




<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Description </h1>
<table width="100%" bgcolor="#ffffff" cellspacing="0" cellpadding="10" style="border: \
1px solid #b8b5a0">  <tr>
  <td>
   <pre style="margin: 0; padding: 0; white-space: pre-wrap; white-space: \
-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: \
break-word;">One of the janitor projects is to replace strncpy with ast_copy_string \
where possible. As a brief example of using the coccinelle tool, I thought I&#39;d \
post an example for using it. There are some cases of strncpy which where \
ast_copy_string wouldn&#39;t be appropriate--sepcifically when it is used to copy \
non-NULL terminated buffers (instead of memcpy, which should be used for that). Two \
cases that I think should be completely safe are where we have something like \
strncpy(src, dst, ${something} - 1) and strncpy(src, dst, sizeof(src)) (which is a \
bug waiting to happen). 

Here is the coccinelle patch to do the translation:

strncpy.cocci
@@
expression a, b, c;
@@

- strncpy(a, b, c - 1)
+ ast_copy_string(a, b, c)

@@
expression a, b;
@@

- strncpy(a, b, sizeof(a))
+ ast_copy_string(a, b, sizeof(a))

Coccinelle needs a little help with some of the macros in Asterisk--so far it looks \
like the ones in linkedlists.h and app.h give it the most trouble. You can generate a \
macro file to use by doing:

spatch -extract_macros include/asterisk/linkedlists.h &gt; /tmp/spatch.h
spatch -extract_macros include/asterisk/app.h &gt;&gt; /tmp/spatch.h

I&#39;ve found that doing all of the includes sometimes makes it miss stuff for some \
reason...

Then to run the patch file on all the files in the asterisk directory:
spatch -sp_file strncpy.cocci -preprocess -c -in_place -I include/ -local_includes \
-macro_file /tmp/spatch.h -smpl_spacing -dir .

You may have to fix some stuff up manually, but it goes a long way to making things a \
lot easier. This is a simple example of how the channel opaquification is done. \
I&#39;ll write this all up on the Wiki, but am basically just doing a quick brain \
dump before I leave for the night.</pre>  </td>
 </tr>
</table>


<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Testing </h1>
<table width="100%" bgcolor="#ffffff" cellspacing="0" cellpadding="10" style="border: \
1px solid #b8b5a0">  <tr>
  <td>
   <pre style="margin: 0; padding: 0; white-space: pre-wrap; white-space: \
-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: \
break-word;">It compiles.</pre>  </td>
 </tr>
</table>




<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Diffs</b> </h1>
<ul style="margin-left: 3em; padding-left: 0;">

 <li>/trunk/addons/chan_ooh323.c <span style="color: grey">(354785)</span></li>

 <li>/trunk/addons/ooh323c/src/ooCalls.c <span style="color: \
grey">(354785)</span></li>

 <li>/trunk/addons/ooh323c/src/ooCmdChannel.c <span style="color: \
grey">(354785)</span></li>

 <li>/trunk/addons/ooh323c/src/ooh323ep.c <span style="color: \
grey">(354785)</span></li>

 <li>/trunk/addons/ooh323c/src/ooq931.c <span style="color: \
grey">(354785)</span></li>

 <li>/trunk/apps/app_rpt.c <span style="color: grey">(354785)</span></li>

 <li>/trunk/channels/iax2-provision.c <span style="color: grey">(354785)</span></li>

 <li>/trunk/pbx/dundi-parser.c <span style="color: grey">(354785)</span></li>

 <li>/trunk/res/ael/ael_lex.c <span style="color: grey">(354785)</span></li>

 <li>/trunk/res/snmp/agent.c <span style="color: grey">(354785)</span></li>

 <li>/trunk/utils/ael_main.c <span style="color: grey">(354785)</span></li>

 <li>/trunk/utils/astman.c <span style="color: grey">(354785)</span></li>

 <li>/trunk/utils/db1-ast/hash/ndbm.c <span style="color: grey">(354785)</span></li>

 <li>/trunk/utils/muted.c <span style="color: grey">(354785)</span></li>

</ul>

<p><a href="https://reviewboard.asterisk.org/r/1732/diff/" style="margin-left: \
3em;">View Diff</a></p>




  </td>
 </tr>
</table>








  </div>
 </body>
</html>



--
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

asterisk-dev mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-dev

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic