]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: fix a potential divide-by-zero (#37705)
authorAlex <alexguo1023@gmail.com>
Mon, 2 Jun 2025 22:47:49 +0000 (18:47 -0400)
committerGitHub <noreply@github.com>
Mon, 2 Jun 2025 22:47:49 +0000 (07:47 +0900)
In function `tc_init`, hz is parsed from the content of file
`"/proc/net/psched"` and can be 0.
In function `hierarchy_token_bucket_class_verify`, hz is directly used
as a divisor in
`htb->buffer = htb->rate / hz + htb->mtu;` without any check. This adds a check on hz before using it as a divisor.

Co-authored-by: jinyaoguo <guo846@purdue.edu>
src/network/tc/htb.c

index 5c85e1a76d5e68e724576a9265bf40f64567da4f..37c2b9529c4a48251a0c0dcfd65d6ce40755d72d 100644 (file)
@@ -470,6 +470,8 @@ static int hierarchy_token_bucket_class_verify(TClass *tclass) {
         if (r < 0)
                 return log_error_errno(r, "Failed to read /proc/net/psched: %m");
 
+        /* Kernel would never hand us 0 Hz. */
+        assert(hz > 0);
         if (htb->buffer == 0)
                 htb->buffer = htb->rate / hz + htb->mtu;
         if (htb->ceil_buffer == 0)