From fa394301e2119ab594b266346cdc114a67af98d9 Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Tue, 3 May 2016 22:29:03 +0200 Subject: udev: fix build with DEBUG=1 Alternatively, this could perhaps be removed since it was broken for a long time and noone seemed to care. But it was helpful for me today. --- src/udev/udev-rules.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c index 475856db6f..26fa52cf6c 100644 --- a/src/udev/udev-rules.c +++ b/src/udev/udev-rules.c @@ -329,8 +329,8 @@ static void dump_token(struct udev_rules *rules, struct token *token) { enum token_type type = token->type; enum operation_type op = token->key.op; enum string_glob_type glob = token->key.glob; - const char *value = str(rules, token->key.value_off); - const char *attr = &rules->buf[token->key.attr_off]; + const char *value = rules_str(rules, token->key.value_off); + const char *attr = &rules->strbuf->buf[token->key.attr_off]; switch (type) { case TK_RULE: @@ -340,9 +340,9 @@ static void dump_token(struct udev_rules *rules, struct token *token) { unsigned int idx = (tk_ptr - tks_ptr) / sizeof(struct token); log_debug("* RULE %s:%u, token: %u, count: %u, label: '%s'", - &rules->buf[token->rule.filename_off], token->rule.filename_line, + &rules->strbuf->buf[token->rule.filename_off], token->rule.filename_line, idx, token->rule.token_count, - &rules->buf[token->rule.label_off]); + &rules->strbuf->buf[token->rule.label_off]); break; } case TK_M_ACTION: @@ -439,11 +439,11 @@ static void dump_token(struct udev_rules *rules, struct token *token) { static void dump_rules(struct udev_rules *rules) { unsigned int i; - log_debug("dumping %u (%zu bytes) tokens, %u (%zu bytes) strings", + log_debug("dumping %u (%zu bytes) tokens, %zu (%zu bytes) strings", rules->token_cur, rules->token_cur * sizeof(struct token), - rules->buf_count, - rules->buf_cur); + rules->strbuf->nodes_count, + rules->strbuf->len); for (i = 0; i < rules->token_cur; i++) dump_token(rules, &rules->tokens[i]); } -- cgit v1.2.3-54-g00ecf From c45606eb95a7171b0dc801e91d35034957ad5e9e Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Tue, 3 May 2016 22:15:49 +0200 Subject: strbuf: set the proper character when creating new nodes Commit 82501b3fc added an early break when a terminal node is found to incorrect place -- before setting c. This caused trie to be built that does not correspond to what it points to in buffer, causing incorrect deduplications: # cat /etc/udev/rules.d/99-bug.rules ENV{FOO}=="0" ENV{xx0}=="BAR" ENV{BAZ}=="00" # udevadm test * RULE /etc/udev/rules.d/99-bug.rules:1, token: 0, count: 2, label: '' M ENV match 'FOO' '0'(plain) * RULE /etc/udev/rules.d/99-bug.rules:2, token: 2, count: 2, label: '' M ENV match 'xx0' 'BAR'(plain) * RULE /etc/udev/rules.d/99-bug.rules:3, token: 4, count: 2, label: '' M ENV match 'BAZ' 'x0'(plain) * END The addition of "xx0" following "0" will cause a trie like this to be created: c=\0 c=0 "0" c=0 "xx0" <-- note the c is incorrect here, causing "00" to be c=O "FOO" deduplicated to it c=R "BAR" This in effect caused the usb_modeswitch rule for Huawei modems to never match and this never be switched to serial mode from mass storage. --- src/basic/strbuf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/basic/strbuf.c b/src/basic/strbuf.c index 797f00cf71..4bef87d3c2 100644 --- a/src/basic/strbuf.c +++ b/src/basic/strbuf.c @@ -156,12 +156,13 @@ ssize_t strbuf_add_string(struct strbuf *str, const char *s, size_t len) { return off; } + c = s[len - 1 - depth]; + /* bsearch is not allowed on a NULL sequence */ if (node->children_count == 0) break; /* lookup child node */ - c = s[len - 1 - depth]; search.c = c; child = bsearch(&search, node->children, node->children_count, sizeof(struct strbuf_child_entry), -- cgit v1.2.3-54-g00ecf