From patchwork Wed Aug 31 07:46:09 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cheng Renquan X-Patchwork-Id: 1115232 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p7V7jSBD008560 for ; Wed, 31 Aug 2011 07:48:21 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754773Ab1HaHsV (ORCPT ); Wed, 31 Aug 2011 03:48:21 -0400 Received: from mail-iy0-f174.google.com ([209.85.210.174]:38180 "EHLO mail-iy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754561Ab1HaHsV (ORCPT ); Wed, 31 Aug 2011 03:48:21 -0400 Received: by mail-iy0-f174.google.com with SMTP id u26so499798iab.19 for ; Wed, 31 Aug 2011 00:48:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=8svNJp4AhdE7mvHJX28t6pg4Whwse0Rkw+AvDCdAGyQ=; b=G2N4BnJUdjHRmgBfY/TlMG6lV6cHaFeR6le7Bp4PEqxl5A05L9AOhhW3mQvYTlTIlb tJQCMxdyU2SEd8gjcpUO7bjtCCGe6rb7kfuIJFLRrYXwX2jmFfH7o2RjMovbsqc4b71R stLEvEFG49tJrgT3a3/3lkGYtr5afhA5cRUYk= Received: by 10.231.75.99 with SMTP id x35mr197645ibj.50.1314776900872; Wed, 31 Aug 2011 00:48:20 -0700 (PDT) Received: from localhost.localdomain ([67.188.70.153]) by mx.google.com with ESMTPS id m21sm3608665ibf.59.2011.08.31.00.48.18 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 31 Aug 2011 00:48:19 -0700 (PDT) From: Cheng Renquan To: linux-kbuild@vger.kernel.org, Arnaud Lacombe Cc: Sam Ravnborg , Michal Marek , Nir Tzachar , Randy Dunlap , c.rq541@comcast.net Subject: [PATCH V2 2/6] scripts/kconfig/nconf: fix memmove's length arg Date: Wed, 31 Aug 2011 00:46:09 -0700 Message-Id: <1314776773-9560-3-git-send-email-crquan@gmail.com> X-Mailer: git-send-email 1.7.6 In-Reply-To: <1314776773-9560-2-git-send-email-crquan@gmail.com> References: <1314776773-9560-1-git-send-email-crquan@gmail.com> <1314776773-9560-2-git-send-email-crquan@gmail.com> Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Wed, 31 Aug 2011 07:48:21 +0000 (UTC) In case KEY_BACKSPACE / KEY_DC to delete a char, it memmove only (len-cursor_position+1) bytes; the default case is to insert a char, it should also memmove exactly (len-cursor_position+1) bytes; the original use of (len+1) is wrong and may access following memory that doesn't belong to result, may cause SegFault in theory; case KEY_BACKSPACE: if (cursor_position > 0) { memmove(&result[cursor_position-1], &result[cursor_position], len-cursor_position+1); cursor_position--; } break; case KEY_DC: if (cursor_position >= 0 && cursor_position < len) { memmove(&result[cursor_position], &result[cursor_position+1], len-cursor_position+1); } break; default: if ((isgraph(res) || isspace(res)) && len-2 < result_len) { /* insert the char at the proper position */ memmove(&result[cursor_position+1], &result[cursor_position], len-cursor_position+1); result[cursor_position] = res; cursor_position++; } Signed-off-by: Cheng Renquan Acked-by: Nir Tzachar --- scripts/kconfig/nconf.gui.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/scripts/kconfig/nconf.gui.c b/scripts/kconfig/nconf.gui.c index d3af04e..3ce2a7c 100644 --- a/scripts/kconfig/nconf.gui.c +++ b/scripts/kconfig/nconf.gui.c @@ -457,7 +457,7 @@ int dialog_inputbox(WINDOW *main_window, /* insert the char at the proper position */ memmove(&result[cursor_position+1], &result[cursor_position], - len+1); + len-cursor_position+1); result[cursor_position] = res; cursor_position++; } else {