All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Christian Göttsche" <cgzones@googlemail.com>
To: selinux@vger.kernel.org
Subject: [PATCH 11/11] setfiles: avoid unsigned integer underflow
Date: Tue, 19 Dec 2023 17:09:33 +0100	[thread overview]
Message-ID: <20231219160943.334370-11-cgzones@googlemail.com> (raw)
In-Reply-To: <20231219160943.334370-1-cgzones@googlemail.com>

While well-defined unsigned integer underflow might signal a logic
mistake or processing of unchecked user input.  Please Clang's undefined
behavior sanitizer:

    restore.c:91:37: runtime error: unsigned integer overflow: 1 - 2 cannot be represented in type 'unsigned long'

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
---
 policycoreutils/setfiles/restore.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/policycoreutils/setfiles/restore.c b/policycoreutils/setfiles/restore.c
index 6131f46a..d045e948 100644
--- a/policycoreutils/setfiles/restore.c
+++ b/policycoreutils/setfiles/restore.c
@@ -77,8 +77,8 @@ int process_glob(char *name, struct restore_opts *opts, size_t nthreads,
 		 long unsigned *skipped_errors)
 {
 	glob_t globbuf;
-	size_t i = 0;
-	int len, rc, errors;
+	size_t i, len;
+	int rc, errors;
 
 	memset(&globbuf, 0, sizeof(globbuf));
 
@@ -88,10 +88,10 @@ int process_glob(char *name, struct restore_opts *opts, size_t nthreads,
 		return errors;
 
 	for (i = 0; i < globbuf.gl_pathc; i++) {
-		len = strlen(globbuf.gl_pathv[i]) - 2;
-		if (len > 0 && strcmp(&globbuf.gl_pathv[i][len--], "/.") == 0)
+		len = strlen(globbuf.gl_pathv[i]);
+		if (len > 2 && strcmp(&globbuf.gl_pathv[i][len - 2], "/.") == 0)
 			continue;
-		if (len > 0 && strcmp(&globbuf.gl_pathv[i][len], "/..") == 0)
+		if (len > 3 && strcmp(&globbuf.gl_pathv[i][len - 3], "/..") == 0)
 			continue;
 		rc = selinux_restorecon_parallel(globbuf.gl_pathv[i],
 						 opts->restorecon_flags,
-- 
2.43.0


  parent reply	other threads:[~2023-12-19 16:10 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-19 16:09 [PATCH 01/11] libselinux/man: mention errno for regex compilation failure Christian Göttsche
2023-12-19 16:09 ` [PATCH 02/11] libselinux/man: sync selinux_check_securetty_context(3) Christian Göttsche
2023-12-19 16:09 ` [PATCH 03/11] libselinux/utils: free allocated resources Christian Göttsche
2023-12-19 16:09 ` [PATCH 04/11] libselinux/utils: improve compute_av output Christian Göttsche
2023-12-19 16:09 ` [PATCH 05/11] libselinux: align SELABEL_OPT_DIGEST usage with man page Christian Göttsche
2023-12-19 16:09 ` [PATCH 06/11] libselinux: fail selabel_open(3) on invalid option Christian Göttsche
2023-12-19 16:09 ` [PATCH 07/11] libselinux: use logging wrapper in getseuser(3) and get_default_context(3) family Christian Göttsche
2023-12-19 16:09 ` [PATCH 08/11] libselinux: support huge passwd/group entries Christian Göttsche
2023-12-19 16:09 ` [PATCH 09/11] libsemanage: support huge passwd entries Christian Göttsche
2023-12-19 16:09 ` [PATCH 10/11] libselinux: enable usage with pedantic UB sanitizers Christian Göttsche
2023-12-19 16:09 ` Christian Göttsche [this message]
2024-01-05 19:15 ` [PATCH 01/11] libselinux/man: mention errno for regex compilation failure James Carter
2024-01-25 19:55   ` James Carter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231219160943.334370-11-cgzones@googlemail.com \
    --to=cgzones@googlemail.com \
    --cc=selinux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.