From fda246681611ad36eb71636e653c6f79ac27ff8f Mon Sep 17 00:00:00 2001 From: Vic Yang Date: Tue, 3 Jul 2012 10:58:23 +0800 Subject: [PATCH] Prevent strzcpy access out-of-bound When parameter 'len' is smaller or equal to 0, do not null-terminate. BUG=chrome-os-partner:11041 TEST=Build success. Change-Id: Ia5267e7d31e3ade8828ba0bc2d68405b4cd236be Reviewed-on: https://gerrit.chromium.org/gerrit/26640 Reviewed-by: Randall Spangler Commit-Ready: Vic Yang Tested-by: Vic Yang --- common/util.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/common/util.c b/common/util.c index b8afdf45c9..69cdf1db64 100644 --- a/common/util.c +++ b/common/util.c @@ -184,6 +184,8 @@ void *memmove(void *dest, const void *src, int len) char *strzcpy(char *dest, const char *src, int len) { char *d = dest; + if (len <= 0) + return dest; while (len > 1 && *src) { *(d++) = *(src++); len--;