From: Emil Velikov Subject: [PATCH 2/3] nouveau: sanitise NOUVEAU_LIBDRM_*_LIMIT_PERCENT input Date: Wed, 12 Mar 2014 20:45:44 +0000 Message-ID: <1394657145-2638-2-git-send-email-emil.l.velikov@gmail.com> References: <1394657145-2638-1-git-send-email-emil.l.velikov@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail-wi0-f169.google.com (mail-wi0-f169.google.com [209.85.212.169]) by gabe.freedesktop.org (Postfix) with ESMTP id 69792FAC61 for ; Wed, 12 Mar 2014 13:44:12 -0700 (PDT) Received: by mail-wi0-f169.google.com with SMTP id hm4so2719816wib.2 for ; Wed, 12 Mar 2014 13:44:10 -0700 (PDT) In-Reply-To: <1394657145-2638-1-git-send-email-emil.l.velikov@gmail.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dri-devel-bounces@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org To: dri-devel@lists.freedesktop.org Cc: emil.l.velikov@gmail.com List-Id: dri-devel@lists.freedesktop.org Current handling relies on atoi which does not detect errors additionally, any integer value will be considered as a valid percent. Resolve that by using strtol and limiting the value within the 5-100 (percent) range. Signed-off-by: Emil Velikov --- nouveau/nouveau.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/nouveau/nouveau.c b/nouveau/nouveau.c index d6013db..06cd804 100644 --- a/nouveau/nouveau.c +++ b/nouveau/nouveau.c @@ -76,7 +76,7 @@ nouveau_device_wrap(int fd, int close, struct nouveau_device **pdev) struct nouveau_device *dev = &nvdev->base; uint64_t chipset, vram, gart, bousage; drmVersionPtr ver; - int ret; + int ret, limit; char *tmp; #ifdef DEBUG @@ -121,16 +121,22 @@ nouveau_device_wrap(int fd, int close, struct nouveau_device **pdev) nvdev->close = close; + nvdev->vram_limit_percent = 80; tmp = getenv("NOUVEAU_LIBDRM_VRAM_LIMIT_PERCENT"); - if (tmp) - nvdev->vram_limit_percent = atoi(tmp); - else - nvdev->vram_limit_percent = 80; + if (tmp) { + limit = strtol(tmp, NULL, 10); + if (limit >= 5 && limit <= 100) + nvdev->vram_limit_percent = limit; + } + + nvdev->gart_limit_percent = 80; tmp = getenv("NOUVEAU_LIBDRM_GART_LIMIT_PERCENT"); - if (tmp) - nvdev->gart_limit_percent = atoi(tmp); - else - nvdev->gart_limit_percent = 80; + if (tmp) { + limit = strtol(tmp, NULL, 10); + if (limit >= 5 && limit <= 100) + nvdev->gart_limit_percent = limit; + } + DRMINITLISTHEAD(&nvdev->bo_list); nvdev->base.object.oclass = NOUVEAU_DEVICE_CLASS; nvdev->base.lib_version = 0x01000000; -- 1.9.0