Commit 9238c209 authored by Jim Meyering's avatar Jim Meyering Committed by Anthony Liguori
Browse files

virtio-9p: avoid unwarranted uses of strncpy



In all of these cases, the uses of strncpy were unnecessary, since
at each point of use we know that the NUL-terminated source bytes
fit in the destination buffer.  Use memcpy in place of strncpy.

Acked-by: default avatarAneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: default avatarJim Meyering <meyering@redhat.com>
Signed-off-by: default avatarAnthony Liguori <aliguori@us.ibm.com>
parent e5fda038
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -44,7 +44,8 @@ static ssize_t mp_pacl_listxattr(FsContext *ctx, const char *path,
        return -1;
    }

    strncpy(value, ACL_ACCESS, len);
    /* len includes the trailing NUL */
    memcpy(value, ACL_ACCESS, len);
    return 0;
}

@@ -95,7 +96,8 @@ static ssize_t mp_dacl_listxattr(FsContext *ctx, const char *path,
        return -1;
    }

    strncpy(value, ACL_DEFAULT, len);
    /* len includes the trailing NUL */
    memcpy(value, ACL_ACCESS, len);
    return 0;
}

+2 −1
Original line number Diff line number Diff line
@@ -61,7 +61,8 @@ static ssize_t mp_user_listxattr(FsContext *ctx, const char *path,
        return -1;
    }

    strncpy(value, name, name_size);
    /* name_size includes the trailing NUL. */
    memcpy(value, name, name_size);
    return name_size;
}

+2 −1
Original line number Diff line number Diff line
@@ -53,7 +53,8 @@ ssize_t pt_listxattr(FsContext *ctx, const char *path,
        return -1;
    }

    strncpy(value, name, name_size);
    /* no need for strncpy: name_size is strlen(name)+1 */
    memcpy(value, name, name_size);
    return name_size;
}