From 96f09654e4f73e79baafdc93df1f0a926d9f342a Mon Sep 17 00:00:00 2001 From: Abdelrahman Daim Date: Wed, 25 Sep 2024 09:04:56 -0700 Subject: [PATCH] [Native Lint] Destination buffer is not null terminated explicitly. (strncpy) Summary: As a good practice, let's make sure that the "kill_desc" buffer is always null-terminated, even if its size changes in the future. Test: Successful build on master. Change-Id: I68a0dc346ea26126a1581994f9c508980a6ac408 Signed-off-by: Abdelrahman Daim --- lmkd.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lmkd.cpp b/lmkd.cpp index 1030147..ef68a94 100644 --- a/lmkd.cpp +++ b/lmkd.cpp @@ -2877,6 +2877,7 @@ update_watermarks: min_score_adj = pressure_after_kill_min_score; kill_reason = PRESSURE_AFTER_KILL; strncpy(kill_desc, "min watermark is breached even after kill", sizeof(kill_desc)); + kill_desc[sizeof(kill_desc) - 1] = '\0'; } else if (level == VMPRESS_LEVEL_CRITICAL && events != 0) { /* * Device is too busy reclaiming memory which might lead to ANR. @@ -2885,6 +2886,7 @@ update_watermarks: */ kill_reason = NOT_RESPONDING; strncpy(kill_desc, "device is not responding", sizeof(kill_desc)); + kill_desc[sizeof(kill_desc) - 1] = '\0'; } else if (swap_is_low && thrashing > thrashing_limit_pct) { /* Page cache is thrashing while swap is low */ kill_reason = LOW_SWAP_AND_THRASHING;