Skip to contentSkip to conversation

hamradio: Fix wrong assignment of 'bbc->cfg.loopback'

PATCH Applied Meng Tang 3 participants 3 messages Mar 15, 2022 – Mar 17, 2022

Subsystems (2)
lore
Share & tools
lore

Meng Tang

author
#0 lore raw

PATCH 1/1 hamradio: Fix wrong assignment of 'bbc->cfg.loopback'

In file hamradio/baycom_epp.c, the baycom_setmode interface, there is a problem with improper use of strstr.

Suppose that when modestr="noloopback", both conditions which are 'strstr(modestr,"noloopback")' and 'strstr(modestr,"loopback")' will be true(not NULL), this lead the bc->cfg.loopback variable will be first assigned to 0, and then reassigned to 1.

This will cause 'bc->cfg.loopback = 0' will never take effect. That obviously violates the logic of the code, so adjust the order of their execution to solve the problem.

---
 drivers/net/hamradio/baycom_epp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/hamradio/baycom_epp.c +2 -2
index a03d0b474641..36e6de42ae77 100644
@@ -982,10 +982,10 @@ static int baycom_setmode(struct baycom_state *bc, const char *modestr)
 		bc->cfg.extmodem = 0;
 	if (strstr(modestr,"extmodem"))
 		bc->cfg.extmodem = 1;
-	if (strstr(modestr,"noloopback"))
-		bc->cfg.loopback = 0;
 	if (strstr(modestr,"loopback"))
 		bc->cfg.loopback = 1;
+	if (strstr(modestr, "noloopback"))
+		bc->cfg.loopback = 0;
 	if ((cp = strstr(modestr,"fclk="))) {
 		bc->cfg.fclk = simple_strtoul(cp+5, NULL, 0);
 		if (bc->cfg.fclk < 1000000)
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Meng Tang

In file hamradio/baycom_epp.c, the baycom_setmode interface, there is a problem with improper use of strstr.

Suppose that when modestr="noloopback", both conditions which are 'strstr(modestr,"noloopback")' and 'strstr(modestr,"loopback")' will be true(not NULL), this lead the bc->cfg.loopback variable will be first assigned to 0, and then reassigned to 1.

Quoted 5 lines

This will cause 'bc->cfg.loopback = 0' will never take effect. That obviously violates the logic of the code, so adjust the order of their execution to solve the problem.

This bug predates git. :P Did you find it by testing or reviewing the code?

regards,
dan carpenter

#2 lore raw
In reply to Meng Tang
This patch was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Tue, 15 Mar 2022 15:48:51 +0800 you wrote:

In file hamradio/baycom_epp.c, the baycom_setmode interface, there is a problem with improper use of strstr.

Suppose that when modestr="noloopback", both conditions which are 'strstr(modestr,"noloopback")' and 'strstr(modestr,"loopback")' will be true(not NULL), this lead the bc->cfg.loopback variable will be first assigned to 0, and then reassigned to 1.

[...]

Here is the summary with links:
- hamradio: Fix wrong assignment of 'bbc->cfg.loopback'

    https://git.kernel.org/netdev/net-next/c/a8df216630fe

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html