]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fdisk: fix copy from readline and whitespace stripping
authorVaclav Dolezal <vdolezal@redhat.com>
Mon, 28 Aug 2017 11:20:34 +0000 (13:20 +0200)
committerVaclav Dolezal <vdolezal@redhat.com>
Mon, 28 Aug 2017 12:06:15 +0000 (14:06 +0200)
Bug fixed:
---
678: fdisk:      ASK: asking for number ['Partition number', <1,4>, default=1, range: 1-4]
678: fdisk:      ASK: asking for user replay [interactive]
Partition number (1-4, default 1): 12345
678: fdisk:      ASK: user's reply: >>>12345<<<
Value out of range.
678: fdisk:      ASK: asking for user replay [interactive]
Partition number (1-4, default 1): 1
678: fdisk:      ASK: user's reply: >>>12345<<<
Value out of range.
678: fdisk:      ASK: asking for user replay [interactive]
Partition number (1-4, default 1):
678: fdisk:      ASK: user's reply: >>>22345<<<
Value out of range.
---

Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
disk-utils/fdisk.c

index 261d884bebeca66ad8f5926915928a698505eed5..be8f00edc904eca8ef77b9d4f36989592cfe2dc7 100644 (file)
@@ -140,10 +140,10 @@ int get_user_reply(const char *prompt, char *buf, size_t bufsz)
                        if (!reply_running && reply_line) {
                                sz = strlen(reply_line);
                                if (sz == 0)
-                                       buf[0] = '\n';
+                                       buf[sz++] = '\n';
                                else
                                        memcpy(buf, reply_line, min(sz, bufsz));
-                               buf[bufsz - 1] = '\0';
+                               buf[min(sz, bufsz - 1)] = '\0';
                                free(reply_line);
                                reply_line = NULL;
                        }
@@ -168,7 +168,7 @@ int get_user_reply(const char *prompt, char *buf, size_t bufsz)
        for (p = buf; *p && !isgraph(*p); p++); /* get first non-blank */
 
        if (p > buf)
-               memmove(buf, p, p - buf);       /* remove blank space */
+               memmove(buf, p, strlen(p) + 1); /* remove blank space */
        sz = strlen(buf);
        if (sz && *(buf + sz - 1) == '\n')
                *(buf + sz - 1) = '\0';