Re: cfdisk: get_string not calculating correct limits with wide ncurses

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Jul 19, 2010 at 03:15:04PM -0400, Mike Frysinger wrote:
> if you load up cfdisk and then try to change the partition type, the input 
> field only allows for inputting 1 character instead of the required 2.  
> building against narrow ncurses gives correct behavior.
> 
> to reproduce:
> 	- build util-linux against wide ncurses
> 	- run cfdisk on a partitioned disk
> 	- select an existing partition
> 	- select Type
> 	- notice that you can only input 1 char
> 
> seems like the calculation in get_string() wrt the incoming limit is slightly 
> off, but i'm not familiar enough with this code to propose a correct patch.

 There was N+1 bug. The original non-wide get_string() function didn't
 count \0. The "Enter filesystem type:" dialog depended on this broken
 behavior.

 The new wide-char code counts also \0, so the bug in the dialog was
 visible with wide-char support.

    Karel


>From 54a0fe298b4d6d948cffbd6fbbbe7dbabc9a6bb1 Mon Sep 17 00:00:00 2001
From: Karel Zak <kzak@xxxxxxxxxx>
Date: Mon, 19 Jul 2010 22:52:58 +0200
Subject: [PATCH] cfdisk: get_string not calculating correct limits

Reported-by: James L. Hammons <jlhamm@xxxxxxx>
Signed-off-by: Karel Zak <kzak@xxxxxxxxxx>
---
 fdisk/cfdisk.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/fdisk/cfdisk.c b/fdisk/cfdisk.c
index 7fa0b19..e7955fe 100644
--- a/fdisk/cfdisk.c
+++ b/fdisk/cfdisk.c
@@ -421,6 +421,11 @@ fdexit(int ret) {
     exit(ret);
 }
 
+/*
+ * Note that @len is size of @str buffer.
+ *
+ * Returns number of read bytes (without \0).
+ */
 static int
 get_string(char *str, int len, char *def) {
     size_t cells = 0, i = 0;
@@ -472,7 +477,7 @@ get_string(char *str, int len, char *def) {
 	    break;
 	default:
 #if defined(HAVE_LIBNCURSESW) && defined(HAVE_WIDECHAR)
-	    if (i < len && iswprint(c)) {
+	    if (i + 1 < len && iswprint(c)) {
 		wchar_t wc = (wchar_t) c;
 		char s[MB_CUR_MAX + 1];
 		int  sz = wctomb(s, wc);
@@ -492,7 +497,7 @@ get_string(char *str, int len, char *def) {
 			putchar(BELL);
 	    }
 #else
-	    if (i < len && isprint(c)) {
+	    if (i + 1 < len && isprint(c)) {
 	        mvaddch(y, x + cells, c);
 		if (use_def) {
 		    clrtoeol();
@@ -2405,7 +2410,7 @@ change_id(int i) {
 
     sprintf(def, "%02X", new_id);
     mvaddstr(COMMAND_LINE_Y, COMMAND_LINE_X, _("Enter filesystem type: "));
-    if ((len = get_string(id, 2, def)) <= 0 && len != GS_DEFAULT)
+    if ((len = get_string(id, 3, def)) <= 0 && len != GS_DEFAULT)
 	return;
 
     if (len != GS_DEFAULT) {
-- 
1.6.6.1

--
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux