Skip to content

Commit 5b2d137

Browse files
dubeykoidryomov
authored andcommitted
ceph: fix overflowed constant issue in ceph_do_objects_copy()
The Coverity Scan service has detected overflowed constant issue in ceph_do_objects_copy() [1]. The CID 1624308 defect contains explanation: "The overflowed value due to arithmetic on constants is too small or unexpectedly negative, causing incorrect computations. Expression bytes, which is equal to -95, where ret is known to be equal to -95, underflows the type that receives it, an unsigned integer 64 bits wide. In ceph_do_objects_copy: Integer overflow occurs in arithmetic on constant operands (CWE-190)". The patch changes the type of bytes variable from size_t to ssize_t with the goal of to be capable to receive negative values. [1] https://scan5.scan.coverity.com/#/project-view/64304/10063?selectedIssue=1624308 Signed-off-by: Viacheslav Dubeyko <[email protected]> Reviewed-by: Alex Markuze <[email protected]> Signed-off-by: Ilya Dryomov <[email protected]>
1 parent 1ed4471 commit 5b2d137

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

fs/ceph/file.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2880,7 +2880,7 @@ static ssize_t ceph_do_objects_copy(struct ceph_inode_info *src_ci, u64 *src_off
28802880
struct ceph_object_id src_oid, dst_oid;
28812881
struct ceph_osd_client *osdc;
28822882
struct ceph_osd_request *req;
2883-
size_t bytes = 0;
2883+
ssize_t bytes = 0;
28842884
u64 src_objnum, src_objoff, dst_objnum, dst_objoff;
28852885
u32 src_objlen, dst_objlen;
28862886
u32 object_size = src_ci->i_layout.object_size;
@@ -2930,7 +2930,7 @@ static ssize_t ceph_do_objects_copy(struct ceph_inode_info *src_ci, u64 *src_off
29302930
"OSDs don't support copy-from2; disabling copy offload\n");
29312931
}
29322932
doutc(cl, "returned %d\n", ret);
2933-
if (!bytes)
2933+
if (bytes <= 0)
29342934
bytes = ret;
29352935
goto out;
29362936
}

0 commit comments

Comments
 (0)