teknoraver / rpms / systemd

Forked from rpms/systemd 3 months ago
Clone

Blame SOURCES/0815-shared-seccomp-reduce-scope-of-indexing-variables.patch

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