b7dd4d
From 64705366e134f06438e88f0b7fbef341d0a01431 Mon Sep 17 00:00:00 2001
b7dd4d
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
b7dd4d
Date: Wed, 19 Aug 2020 17:43:40 +0200
b7dd4d
Subject: [PATCH] shared/seccomp: reduce scope of indexing variables
b7dd4d
b7dd4d
(cherry picked from commit 077e8fc0cad5a4532348d20a1eef8621295dd75a)
b7dd4d
b7dd4d
Related: #2040247
b7dd4d
---
b7dd4d
 src/shared/seccomp-util.c | 14 +++++---------
b7dd4d
 1 file changed, 5 insertions(+), 9 deletions(-)
b7dd4d
b7dd4d
diff --git a/src/shared/seccomp-util.c b/src/shared/seccomp-util.c
b7dd4d
index c2b2f2da92..4d2ba31d47 100644
b7dd4d
--- a/src/shared/seccomp-util.c
b7dd4d
+++ b/src/shared/seccomp-util.c
b7dd4d
@@ -864,12 +864,10 @@ const SyscallFilterSet syscall_filter_sets[_SYSCALL_FILTER_SET_MAX] = {
b7dd4d
 };
b7dd4d
 
b7dd4d
 const SyscallFilterSet *syscall_filter_set_find(const char *name) {
b7dd4d
-        unsigned i;
b7dd4d
-
b7dd4d
         if (isempty(name) || name[0] != '@')
b7dd4d
                 return NULL;
b7dd4d
 
b7dd4d
-        for (i = 0; i < _SYSCALL_FILTER_SET_MAX; i++)
b7dd4d
+        for (unsigned i = 0; i < _SYSCALL_FILTER_SET_MAX; i++)
b7dd4d
                 if (streq(syscall_filter_sets[i].name, name))
b7dd4d
                         return syscall_filter_sets + i;
b7dd4d
 
b7dd4d
@@ -1105,7 +1103,6 @@ int seccomp_restrict_namespaces(unsigned long retain) {
b7dd4d
 
b7dd4d
         SECCOMP_FOREACH_LOCAL_ARCH(arch) {
b7dd4d
                 _cleanup_(seccomp_releasep) scmp_filter_ctx seccomp = NULL;
b7dd4d
-                unsigned i;
b7dd4d
 
b7dd4d
                 log_debug("Operating on architecture: %s", seccomp_arch_to_string(arch));
b7dd4d
 
b7dd4d
@@ -1135,7 +1132,7 @@ int seccomp_restrict_namespaces(unsigned long retain) {
b7dd4d
                         continue;
b7dd4d
                 }
b7dd4d
 
b7dd4d
-                for (i = 0; namespace_flag_map[i].name; i++) {
b7dd4d
+                for (unsigned i = 0; namespace_flag_map[i].name; i++) {
b7dd4d
                         unsigned long f;
b7dd4d
 
b7dd4d
                         f = namespace_flag_map[i].flag;
b7dd4d
@@ -1288,7 +1285,7 @@ int seccomp_restrict_address_families(Set *address_families, bool whitelist) {
b7dd4d
                         return r;
b7dd4d
 
b7dd4d
                 if (whitelist) {
b7dd4d
-                        int af, first = 0, last = 0;
b7dd4d
+                        int first = 0, last = 0;
b7dd4d
                         void *afp;
b7dd4d
 
b7dd4d
                         /* If this is a whitelist, we first block the address families that are out of range and then
b7dd4d
@@ -1296,7 +1293,7 @@ int seccomp_restrict_address_families(Set *address_families, bool whitelist) {
b7dd4d
                          * the set. */
b7dd4d
 
b7dd4d
                         SET_FOREACH(afp, address_families, i) {
b7dd4d
-                                af = PTR_TO_INT(afp);
b7dd4d
+                                int af = PTR_TO_INT(afp);
b7dd4d
 
b7dd4d
                                 if (af <= 0 || af >= af_max())
b7dd4d
                                         continue;
b7dd4d
@@ -1350,7 +1347,7 @@ int seccomp_restrict_address_families(Set *address_families, bool whitelist) {
b7dd4d
                                 }
b7dd4d
 
b7dd4d
                                 /* Block everything between the first and last entry */
b7dd4d
-                                for (af = 1; af < af_max(); af++) {
b7dd4d
+                                for (int af = 1; af < af_max(); af++) {
b7dd4d
 
b7dd4d
                                         if (set_contains(address_families, INT_TO_PTR(af)))
b7dd4d
                                                 continue;
b7dd4d
@@ -1378,7 +1375,6 @@ int seccomp_restrict_address_families(Set *address_families, bool whitelist) {
b7dd4d
                          * checks. */
b7dd4d
 
b7dd4d
                         SET_FOREACH(af, address_families, i) {
b7dd4d
-
b7dd4d
                                 r = seccomp_rule_add_exact(
b7dd4d
                                                 seccomp,
b7dd4d
                                                 SCMP_ACT_ERRNO(EAFNOSUPPORT),