chiark / gitweb /
use memzero(foo, length); for all memset(foo, 0, length); calls
[elogind.git] / src / udev / udev-rules.c
index 8d2b057e2f6c4ab0d3726eb51c92c3ed5430e9e1..e90829811bff15376a9051bc3084313704ca0ae9 100644 (file)
@@ -870,7 +870,7 @@ static int rule_add_key(struct rule_tmp *rule_tmp, enum token_type type,
         struct token *token = &rule_tmp->token[rule_tmp->token_cur];
         const char *attr = NULL;
 
-        memset(token, 0x00, sizeof(struct token));
+        memzero(token, sizeof(struct token));
 
         switch (type) {
         case TK_M_ACTION:
@@ -900,6 +900,7 @@ static int rule_add_key(struct rule_tmp *rule_tmp, enum token_type type,
         case TK_A_GOTO:
         case TK_M_TAG:
         case TK_A_TAG:
+        case TK_A_STATIC_NODE:
                 token->key.value_off = rules_add_string(rule_tmp->rules, value);
                 break;
         case TK_M_IMPORT_BUILTIN:
@@ -943,9 +944,6 @@ static int rule_add_key(struct rule_tmp *rule_tmp, enum token_type type,
         case TK_A_MODE_ID:
                 token->key.mode = *(mode_t *)data;
                 break;
-        case TK_A_STATIC_NODE:
-                token->key.value_off = rules_add_string(rule_tmp->rules, value);
-                break;
         case TK_M_EVENT_TIMEOUT:
                 token->key.event_timeout = *(int *)data;
                 break;
@@ -993,7 +991,7 @@ static int rule_add_key(struct rule_tmp *rule_tmp, enum token_type type,
         }
 
         if (attr != NULL) {
-                /* check if property/attribut name has substitution chars */
+                /* check if property/attribute name has substitution chars */
                 if (attr[0] == '[')
                         token->key.attrsubst = SB_SUBSYS;
                 else if (strchr(attr, '%') != NULL || strchr(attr, '$') != NULL)
@@ -1054,7 +1052,7 @@ static int add_rule(struct udev_rules *rules, char *line,
         const char *attr;
         struct rule_tmp rule_tmp;
 
-        memset(&rule_tmp, 0x00, sizeof(struct rule_tmp));
+        memzero(&rule_tmp, sizeof(struct rule_tmp));
         rule_tmp.rules = rules;
         rule_tmp.rule.type = TK_RULE;
         /* the offset in the rule is limited to unsigned short */
@@ -1654,7 +1652,7 @@ struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names)
 
         strv_free(files);
 
-        memset(&end_token, 0x00, sizeof(struct token));
+        memzero(&end_token, sizeof(struct token));
         end_token.type = TK_END;
         add_token(rules, &end_token);
         log_debug("rules contain %zu bytes tokens (%u * %zu bytes), %zu bytes strings",
@@ -2561,15 +2559,11 @@ int udev_rules_apply_static_dev_perms(struct udev_rules *rules)
                         /* we assure, that the permissions tokens are sorted before the static token */
                         if (mode == 0 && uid == 0 && gid == 0 && tags == NULL)
                                 goto next;
+
                         strscpyl(device_node, sizeof(device_node), "/dev/", rules_str(rules, cur->key.value_off), NULL);
-                        if (stat(device_node, &stats) != 0)
-                                goto next;
-                        if (!S_ISBLK(stats.st_mode) && !S_ISCHR(stats.st_mode))
-                                goto next;
 
+                        /* export the tags to a directory as symlinks, allowing otherwise dead nodes to be tagged */
                         if (tags) {
-                                /* Export the tags to a directory as symlinks, allowing otherwise dead nodes to be tagged */
-
                                 STRV_FOREACH(t, tags) {
                                         _cleanup_free_ char *unescaped_filename = NULL;
 
@@ -2594,7 +2588,12 @@ int udev_rules_apply_static_dev_perms(struct udev_rules *rules)
 
                         /* don't touch the permissions if only the tags were set */
                         if (mode == 0 && uid == 0 && gid == 0)
-                                goto next;
+                                break;
+
+                        if (stat(device_node, &stats) != 0)
+                                break;
+                        if (!S_ISBLK(stats.st_mode) && !S_ISCHR(stats.st_mode))
+                                break;
 
                         if (mode == 0) {
                                 if (gid > 0)