A few functions are well-known that they forward just an input parameter as
their return value.

I imagine that the Coccinelle software can find such implementations that are
similar to an interface style like "strcat()" or "strcpy()" if the corresponding
source files are available for a static code analysis. I hope that a few
functions can be found by this approach that do not perform input parameter
validation usually.

I stumble on the following messages.


elfring@Sonne:~/Projekte/Coccinelle/lokal/demos/pass-through> PAT=pt1.cocci && cat $PAT && LINE='-----' && echo $LINE && SRC=pt1.c && cat $SRC && echo $LINE && spatch -sp_file $PAT $SRC
@pass_through@
identifier function, input;
type data_type;
@@
 data_type function(..., data_type input, ...)
 {
  ...
  return input;
  ...
 }

@@
identifier pass_through.function;
expression result;
type cast;
@@
(
*function(...)
|
*result = (cast) function(...)
)
-----
char* my_copy(char const * source, char* destination)
{
  /* Do something ... */

  return destination;
}

char* my_append(char* prefix, char const * addition)
{
  /* Data adjustment ... */

  return prefix;
}

int main(void)
{
  char buffer[123];

  my_append(my_copy("check", buffer), " this out");
}
-----
init_defs_builtins: /usr/share/coccinelle/standard.h
HANDLING: pt1.c

previous modification:
MINUS
According to environment 2:
   pass_through.function -> id my_copy
   pass_through.function -> id my_copy

current modification:
MINUS
According to environment 2:
   pass_through.function -> id my_append
   pass_through.function -> id my_append

Fatal error: exception Failure("rule starting on line 12: already tagged token:
C code context
File "pt1.c", line 19, column 20,  charpos = 271
around = '"check"', whole content = my_append(my_copy("check", buffer), " this out");")


Do I need to adjust my filter pattern a bit more?


I would also be interested to search for functions that do not perform input parameter validation in a general way. But the corresponding filter pattern will be bigger challenge because it would be needed to determine more implementation details. How do you find out from a function parameter list (with a variable length) by SmPL means which arguments are used as input parameters?

Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to