]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fdisk: initialize buffers for get_user_reply() [coverity scan]
authorKarel Zak <kzak@redhat.com>
Tue, 14 May 2019 13:00:01 +0000 (15:00 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 14 May 2019 13:00:01 +0000 (15:00 +0200)
It's probably unnecessary, but better be safe than sorry.

Signed-off-by: Karel Zak <kzak@redhat.com>
disk-utils/fdisk-menu.c
disk-utils/fdisk.c
disk-utils/sfdisk.c

index a6f43515fb4dd03b28528d21df80d2c754930fc8..cd104e20be1a130c1d08ccce94b6ef64e92c92a5 100644 (file)
@@ -417,7 +417,7 @@ int process_fdisk_menu(struct fdisk_context **cxt0)
        const struct menu *menu;
        int key, rc;
        const char *prompt;
-       char buf[BUFSIZ];
+       char buf[BUFSIZ] = { '\0' };
 
        if (fdisk_is_details(cxt))
                prompt = _("Expert command (m for help): ");
index c27485af2790d8e61edccc1281b5355a4fed371b..380f3f445a2c931d21f65da1a4df2aec886c838e 100644 (file)
@@ -397,7 +397,7 @@ int ask_callback(struct fdisk_context *cxt, struct fdisk_ask *ask,
                    void *data __attribute__((__unused__)))
 {
        int rc = 0;
-       char buf[BUFSIZ];
+       char buf[BUFSIZ] = { '\0' };
 
        assert(cxt);
        assert(ask);
@@ -482,7 +482,7 @@ static struct fdisk_parttype *ask_partition_type(struct fdisk_context *cxt, int
                _("Hex code (type L to list all codes): ") :
                _("Partition type (type L to list all types): ");
        do {
-               char buf[256];
+               char buf[256] = { '\0' };
                int rc = get_user_reply(q, buf, sizeof(buf));
 
                if (rc) {
index 8166137c5407b92c33ce5c73db69d891c32460e8..4a9640d0e37cafc5522a03ae2b8a7d76e83a89ed 100644 (file)
@@ -133,7 +133,7 @@ static int get_user_reply(const char *prompt, char *buf, size_t bufsz)
                p = readline(prompt);
                if (!p)
                        return 1;
-               strncpy(buf, p, bufsz);
+               strncpy(buf, p, bufsz - 1);
                if (bufsz != 0)
                        buf[bufsz - 1] = '\0';
                free(p);
@@ -192,7 +192,7 @@ static int ask_callback(struct fdisk_context *cxt __attribute__((__unused__)),
                break;
        case FDISK_ASKTYPE_YESNO:
        {
-               char buf[BUFSIZ];
+               char buf[BUFSIZ] = { '\0' };
                fputc('\n', stdout);
                do {
                        int x;