]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
basic: fix overflow detection in sigbus_pop
authorRose <83477269+AtariDreams@users.noreply.github.com>
Tue, 2 Jan 2024 15:13:27 +0000 (10:13 -0500)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 3 Jan 2024 20:26:01 +0000 (05:26 +0900)
The current check checks for n_sigbus_queue
being greater than or equal to SIGBUS_QUEUE_MAX,
when it should be just greater than as
n_sigbus_queue being SIGBUS_QUEUE_MAX indicates
that the queue is full, but not overflowed.

src/basic/sigbus.c

index 7e5a493f6b03b57e75c6be10368e588e39f75222..47ab0b81d887622cb769b229fa19da014e9a6205 100644 (file)
@@ -40,14 +40,14 @@ static void sigbus_push(void *addr) {
         }
 
         /* If we can't, make sure the queue size is out of bounds, to
-         * mark it as overflow */
+         * mark it as overflowed */
         for (;;) {
                 sig_atomic_t c;
 
                 __atomic_thread_fence(__ATOMIC_SEQ_CST);
                 c = n_sigbus_queue;
 
-                if (c > SIGBUS_QUEUE_MAX) /* already overflow */
+                if (c > SIGBUS_QUEUE_MAX) /* already overflowed */
                         return;
 
                 /* OK if we clobber c here, since we either immediately return
@@ -70,7 +70,7 @@ int sigbus_pop(void **ret) {
                 if (_likely_(c == 0))
                         return 0;
 
-                if (_unlikely_(c >= SIGBUS_QUEUE_MAX))
+                if (_unlikely_(c > SIGBUS_QUEUE_MAX))
                         return -EOVERFLOW;
 
                 for (u = 0; u < SIGBUS_QUEUE_MAX; u++) {