summaryrefslogtreecommitdiffstats
path: root/src/udev
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2024-06-11 18:16:55 +0200
committerLuca Boccassi <luca.boccassi@gmail.com>2024-06-12 01:07:33 +0200
commit442c6bd4ba6bb207e5cc615c986dee4590e0ce34 (patch)
tree5b49cb460daac42c5bfed2805b52fa5f7ccab700 /src/udev
parentsd-dhcp-server: clear buffer before receive (diff)
downloadsystemd-442c6bd4ba6bb207e5cc615c986dee4590e0ce34.tar.xz
systemd-442c6bd4ba6bb207e5cc615c986dee4590e0ce34.zip
udev: rewrite token_match_attr() to make it easier for Coverity to understand
No functional change. Closes CID#1469719.
Diffstat (limited to 'src/udev')
-rw-r--r--src/udev/udev-rules.c31
1 files changed, 16 insertions, 15 deletions
diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c
index 581bbaf345..366f7ba92c 100644
--- a/src/udev/udev-rules.c
+++ b/src/udev/udev-rules.c
@@ -1771,27 +1771,28 @@ static bool token_match_attr(UdevRuleToken *token, sd_device *dev, UdevEvent *ev
case SUBST_TYPE_PLAIN:
if (sd_device_get_sysattr_value(dev, name, &value) < 0)
return false;
- break;
+
+ /* remove trailing whitespace, if not asked to match for it */
+ if (token->attr_match_remove_trailing_whitespace) {
+ strscpy(vbuf, sizeof(vbuf), value);
+ value = delete_trailing_chars(vbuf, NULL);
+ }
+
+ return token_match_string(token, value);
+
case SUBST_TYPE_SUBSYS:
if (udev_resolve_subsys_kernel(name, vbuf, sizeof(vbuf), true) < 0)
return false;
- value = vbuf;
- break;
- default:
- assert_not_reached();
- }
- /* remove trailing whitespace, if not asked to match for it */
- if (token->attr_match_remove_trailing_whitespace) {
- if (value != vbuf) {
- strscpy(vbuf, sizeof(vbuf), value);
- value = vbuf;
- }
+ /* remove trailing whitespace, if not asked to match for it */
+ if (token->attr_match_remove_trailing_whitespace)
+ delete_trailing_chars(vbuf, NULL);
- delete_trailing_chars(vbuf, NULL);
- }
+ return token_match_string(token, vbuf);
- return token_match_string(token, value);
+ default:
+ assert_not_reached();
+ }
}
static int get_property_from_string(char *line, char **ret_key, char **ret_value) {