From: Arshad Hussain Date: Mon, 10 Jun 2024 08:15:41 +0000 (-0400) Subject: LU-17000 llite: Handle not NUL terminated buffer X-Git-Tag: 2.16.56~56 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=517e76cbefe800251d6d132c7f1d8a0d965d089e;p=fs%2Flustre-release.git LU-17000 llite: Handle not NUL terminated buffer In pcc_expr_time_parse() 'buf' may not have a null terminator if the source string's length is equal to the buffer. This patch handles this. Test-Parameters: trivial testlist=sanity-pcc CoverityID: 426259 ("Buffer not null terminated") Fixes: 3835f4d3 (LU-13881 pcc: comparator support for PCC rules) Signed-off-by: Arshad Hussain Change-Id: Ifc144d73c75b8eef25a994630c600b9c1922aa3b Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/55377 Reviewed-by: Andreas Dilger Reviewed-by: Qian Yingjin Reviewed-by: Oleg Drokin Tested-by: jenkins Tested-by: Maloo --- diff --git a/lustre/llite/pcc.c b/lustre/llite/pcc.c index c7a20be..1cff8d2 100644 --- a/lustre/llite/pcc.c +++ b/lustre/llite/pcc.c @@ -381,14 +381,14 @@ static int pcc_expr_time_parse(char *str, struct pcc_expression *expr) unsigned long mtime; int len = strlen(str); unsigned int mult = 1; - char buf[10]; + char buf[11]; /* +1 for NUL */ int rc; if (expr->pe_opc == PCC_FIELD_OP_EQ) return -EOPNOTSUPP; /* 1B seconds is enough, and avoids the need for overflow checking */ - if (len > 10) + if (len >= sizeof(buf)) return -EOVERFLOW; strncpy(buf, str, sizeof(buf));