Skip to contentSkip to conversation

Detecting unchecked return values (with SmPL)?

RFC Markus Elfring 2 participants 11 messages Nov 30 – Dec 1 Kernel janitors

lore
Share & tools
lore
#0 lore raw

Hello,

Macro and function calls for which a return value is not assigned to a variable can be found also by a script (like the following) for the semantic patch language.

@display@
identifier i;
statement s;
@@
(
*i(...);
&s
)

Some developers and software reviewers care for a corresponding topic.

CWE-252: Unchecked Return Value
https://cwe.mitre.org/data/definitions/252.html

Thus I suggest to refine case distinctions accordingly.

1. Identifiers can eventually be excluded if they would denote items with the return type “void”.

2. Identifiers can eventually be restricted to names that would denote items according to non-void return types.

Which structures would you choose for such data processing purposes?

Regards,
Markus

#1 lore raw
Quoted 5 lines · Markus Elfring

Hello,

Macro and function calls for which a return value is not assigned to a variable can be found also by a script (like the following) for the semantic patch language.

Quoted 7 lines

@display@
identifier i;
statement s;
@@
(
*i(...);
&s

&s seems totally unnecessary.

julia

Quoted 24 lines

)

Some developers and software reviewers care for a corresponding topic.

CWE-252: Unchecked Return Value
https://cwe.mitre.org/data/definitions/252.html

Thus I suggest to refine case distinctions accordingly.

1. Identifiers can eventually be excluded if they would denote items with the return type “void”.

2. Identifiers can eventually be restricted to names that would denote items according to non-void return types.

Which structures would you choose for such data processing purposes?

Regards,
Markus

#2 lore raw
Quoted 11 lines
Quoted 10 lines

Macro and function calls for which a return value is not assigned to a variable can be found also by a script (like the following) for the semantic patch language.

@display@
identifier i;
statement s;
@@
(
*i(...);
&s

Quoted 1 line

&s seems totally unnecessary.

Can the code for the SmPL asterisk alone represent also a source code search for a call where a variable assignment would be attempted?

Or:
Do you expect to specify the variable assignment exclusion in any other ways?

Regards,
Markus

#3 lore raw
Quoted 11 lines · Markus Elfring
Quoted 11 lines
Quoted 10 lines

Macro and function calls for which a return value is not assigned to a variable can be found also by a script (like the following) for the semantic patch language.

@display@
identifier i;
statement s;
@@
(
*i(...);
&s

Quoted 4 lines
Quoted 1 line

&s seems totally unnecessary.

Can the code for the SmPL asterisk alone represent also a source code search for a call where a variable assignment would be attempted?

No. Not with the ;. Coccinelle parses the code. It doesn't search for substrings.

julia

Quoted 7 lines

Or:
Do you expect to specify the variable assignment exclusion in any other ways?

Regards,
Markus

#4 lore raw
In reply to Julia Lawall
Quoted 11 lines
Quoted 10 lines

Macro and function calls for which a return value is not assigned to a variable can be found also by a script (like the following) for the semantic patch language.

@display@
identifier i;
statement s;
@@
(
*i(...);
&s

&s seems totally unnecessary.

Would you find the following SmPL script variant more appropriate for efficient source code searches?

@display2@
expression e;
identifier i;
@@
(e = i(...)
|
*i(...)
);

Would you be looking for more advanced data constraints here?

Regards,
Markus

#5 lore raw
Quoted 26 lines · Markus Elfring
Quoted 11 lines
Quoted 10 lines

Macro and function calls for which a return value is not assigned to a variable can be found also by a script (like the following) for the semantic patch language.

@display@
identifier i;
statement s;
@@
(
*i(...);
&s

&s seems totally unnecessary.

Would you find the following SmPL script variant more appropriate for efficient source code searches?

@display2@
expression e;
identifier i;
@@
(e = i(...)
|
*i(...)
);

Quoted 1 line

Would you be looking for more advanced data constraints here?

*i(...);

seemed completely fine. There is no need to consider the other contexts in which a funcion call can occur.

julia

Quoted 4 lines

Regards,
Markus

#6 lore raw
Quoted 14 lines
Quoted 14 lines

Would you find the following SmPL script variant more appropriate for efficient source code searches?

@display2@
expression e;
identifier i;
@@
(e = i(...)
|
*i(...)
);

Quoted 6 lines
Quoted 1 line

Would you be looking for more advanced data constraints here?

*i(...);

seemed completely fine. There is no need to consider the other contexts in which a funcion call can occur.

Will such information influence the incomplete software documentation any more?

Regards,
Markus

#7 lore raw
Quoted 14 lines · Markus Elfring
Quoted 14 lines
Quoted 14 lines

Would you find the following SmPL script variant more appropriate for efficient source code searches?

@display2@
expression e;
identifier i;
@@
(e = i(...)
|
*i(...)
);

Quoted 7 lines
Quoted 6 lines
Quoted 1 line

Would you be looking for more advanced data constraints here?

*i(...);

seemed completely fine. There is no need to consider the other contexts in which a funcion call can occur.

Will such information influence the incomplete software documentation any more?

I don't think that the documentation is incomplete. The BNF has entries, for statements, expressions, etc. i(...); is only a statement. It is not the right half of an assiment followed by a semicolon. No such nonterminal exists in the C grammar.

julia

#8 lore raw
In reply to Markus Elfring
Quoted 1 line

CWE-252: Unchecked Return Value

How will development interests evolve further if it could be determined also with the help of another script variant (like the following) for the semantic patch language that the software “Linux next-20261127” contains eventually 423 unchecked function calls in 246 source files according to a single selected identifier?

@display@
@@
*clk_prepare_enable(...);

Can any coccicheck script variations become more helpful here?

Regards,
Markus

#10 lore raw
In reply to Markus Elfring
Quoted 1 line

CWE-252: Unchecked Return Value

How will development interests evolve further if it could be determined also with the help of another script variant (like the following) for the semantic patch language that the software “Linux next-20261130” contains unchecked function calls in 24 source files according to a single selected identifier?

@display@
@@
*devm_pm_runtime_enable(...);

How can such information be integrated better into coccicheck script variations?

Regards,
Markus