From patchwork Tue Dec 16 07:00:06 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yousong Zhou X-Patchwork-Id: 422457 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from arrakis.dune.hu (arrakis.dune.hu [78.24.191.176]) (using TLSv1.1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id CBB04140079 for ; Thu, 18 Dec 2014 13:54:58 +1100 (AEDT) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id B780928BC1A; Thu, 18 Dec 2014 03:51:57 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00, DATE_IN_PAST_24_48, FREEMAIL_FROM,T_DKIM_INVALID autolearn=no version=3.3.2 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id B66FA28BBD2 for ; Thu, 18 Dec 2014 03:51:37 +0100 (CET) X-policyd-weight: using cached result; rate: -8.5 Received: from mail-pd0-f169.google.com (mail-pd0-f169.google.com [209.85.192.169]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Thu, 18 Dec 2014 03:51:31 +0100 (CET) Received: by mail-pd0-f169.google.com with SMTP id z10so441096pdj.0 for ; Wed, 17 Dec 2014 18:53:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ooZKlS4Xvx67nSkntnHHUgxdgyKb13AuEbftE1ydztQ=; b=uo3x/z+UIfDMUQODod8rscZKhROckdNrWCltMNplEf6hbcYLxd8E8sXJBr4Lo0h0fP 16pvHlxQvogpoiSaaE7jBRJzXvzlRMJKlIl9fi8UOTBGu1Z22BSYqvmeCljCK0Lzrp/F Fkm3ukrI4m9Lf5aMMZzeb8xHgRpCobwx3DppEzX4bKUHQhQyUHGsTgPIsvVWIY4RP8MD pTrWEvmELBS/EsEfB2PAzsu6VzCtdjFHE4cEboFP8Uc1i7LZsvdJ/FzJjfiFJ7cR3h9l 6GQwKHVHKqniKG05Dsn/y4husR6U0rS6HZApJVrhGx4rc3tSZ1X4+5uJ4hrGCj5VwZKw 9reA== X-Received: by 10.66.162.162 with SMTP id yb2mr4055103pab.46.1418871199738; Wed, 17 Dec 2014 18:53:19 -0800 (PST) Received: from debian.lan ([103.29.140.56]) by mx.google.com with ESMTPSA id oy7sm5104495pbc.88.2014.12.17.18.53.16 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Dec 2014 18:53:18 -0800 (PST) From: Yousong Zhou To: nbd@openwrt.org Date: Tue, 16 Dec 2014 15:00:06 +0800 Message-Id: <1418713218-16300-5-git-send-email-yszhou4tech@gmail.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1418713218-16300-1-git-send-email-yszhou4tech@gmail.com> References: <1418713218-16300-1-git-send-email-yszhou4tech@gmail.com> Cc: openwrt-devel@lists.openwrt.org Subject: [OpenWrt-Devel] [PATCH v2 04/16] file: fix EOF check. X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" Signed-off-by: Yousong Zhou --- file.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/file.c b/file.c index 1d2718a..3f02c11 100644 --- a/file.c +++ b/file.c @@ -48,8 +48,8 @@ __private void uci_getln(struct uci_context *ctx, int offset) pctx->buf = uci_malloc(ctx, LINEBUF); pctx->bufsz = LINEBUF; } - /* `offset' may off by one */ - if (offset >= pctx->bufsz) { + /* It takes 2 slots for fgets to read 1 char. */ + if (offset >= pctx->bufsz - 1) { pctx->bufsz *= 2; pctx->buf = uci_realloc(ctx, pctx->buf, pctx->bufsz); }