Skip to content

Commit 1ed4471

Browse files
dubeykoidryomov
authored andcommitted
ceph: fix wrong sizeof argument issue in register_session()
The Coverity Scan service has detected the wrong sizeof argument in register_session() [1]. The CID 1598909 defect contains explanation: "The wrong sizeof value is used in an expression or as argument to a function. The result is an incorrect value that may cause unexpected program behaviors. In register_session: The sizeof operator is invoked on the wrong argument (CWE-569)". The patch introduces a ptr_size variable that is initialized by sizeof(struct ceph_mds_session *). And this variable is used instead of sizeof(void *) in the code. [1] https://scan5.scan.coverity.com/#/project-view/64304/10063?selectedIssue=1598909 Signed-off-by: Viacheslav Dubeyko <[email protected]> Reviewed-by: Alex Markuze <[email protected]> Signed-off-by: Ilya Dryomov <[email protected]>
1 parent b7ed1e2 commit 1ed4471

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

fs/ceph/mds_client.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -979,14 +979,15 @@ static struct ceph_mds_session *register_session(struct ceph_mds_client *mdsc,
979979
if (mds >= mdsc->max_sessions) {
980980
int newmax = 1 << get_count_order(mds + 1);
981981
struct ceph_mds_session **sa;
982+
size_t ptr_size = sizeof(struct ceph_mds_session *);
982983

983984
doutc(cl, "realloc to %d\n", newmax);
984-
sa = kcalloc(newmax, sizeof(void *), GFP_NOFS);
985+
sa = kcalloc(newmax, ptr_size, GFP_NOFS);
985986
if (!sa)
986987
goto fail_realloc;
987988
if (mdsc->sessions) {
988989
memcpy(sa, mdsc->sessions,
989-
mdsc->max_sessions * sizeof(void *));
990+
mdsc->max_sessions * ptr_size);
990991
kfree(mdsc->sessions);
991992
}
992993
mdsc->sessions = sa;

0 commit comments

Comments
 (0)