-
Notifications
You must be signed in to change notification settings - Fork 308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DAOS-17131 dfs: Possible missing string termination after strncpy function call #15920
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/** | ||
* (C) Copyright 2018-2024 Intel Corporation. | ||
* (C) Copyright 2025 Hewlett Packard Enterprise Development LP | ||
* | ||
* SPDX-License-Identifier: BSD-2-Clause-Patent | ||
*/ | ||
|
@@ -83,7 +84,8 @@ dfs_cont_create(daos_handle_t poh, uuid_t *cuuid, dfs_attr_t *attr, daos_handle_ | |
dattr.da_chunk_size = DFS_DEFAULT_CHUNK_SIZE; | ||
|
||
if (attr->da_hints[0] != 0) { | ||
strncpy(dattr.da_hints, attr->da_hints, DAOS_CONT_HINT_MAX_LEN); | ||
/* DAOS-17042 Replace strncpy with strncat or strlcpy */ | ||
strncpy(dattr.da_hints, attr->da_hints, DAOS_CONT_HINT_MAX_LEN - 1); | ||
dattr.da_hints[DAOS_CONT_HINT_MAX_LEN - 1] = '\0'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The implementation is actually perfectly fine. Are you see any issues with the original code? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, please take a look at #15105 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do think the existing code has a bug. If
Yields There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, finally the string will be somehow OK, but it will be not the same string. The problem of strncpy misusage has been discussed in #15105 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But then again I guess it doesn't matter because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reading up on this more, it's not actually a misuse of strncpy, but just simply that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, doing some local testing, the compiler complains either way. So this change doesn't solve anything With
It complains with
And with
It complains with
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. thanks for the explanation |
||
} | ||
} else { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/** | ||
* (C) Copyright 2018-2024 Intel Corporation. | ||
* (C) Copyright 2025 Hewlett Packard Enterprise Development LP | ||
* | ||
* SPDX-License-Identifier: BSD-2-Clause-Patent | ||
*/ | ||
|
@@ -510,7 +511,9 @@ dfs_dup(dfs_t *dfs, dfs_obj_t *obj, int flags, dfs_obj_t **_new_obj) | |
D_GOTO(err, rc = EINVAL); | ||
} | ||
|
||
strncpy(new_obj->name, obj->name, DFS_MAX_NAME + 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again this is fine too if the I think a serious issue is about the consistency of using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, this is the result of #15105 + see my comment above: #15920 (comment) |
||
/* DAOS-17042 Replace strncpy with strncat or strlcpy */ | ||
strncpy(new_obj->name, obj->name, DFS_MAX_NAME); | ||
new_obj->name[DFS_MAX_NAME] = '\0'; | ||
new_obj->dfs = dfs; | ||
new_obj->mode = obj->mode; | ||
new_obj->flags = flags; | ||
|
@@ -616,8 +619,9 @@ dfs_obj_local2global(dfs_t *dfs, dfs_obj_t *obj, d_iov_t *glob) | |
oid_cp(&obj_glob->parent_oid, obj->parent_oid); | ||
uuid_copy(obj_glob->coh_uuid, coh_uuid); | ||
uuid_copy(obj_glob->cont_uuid, cont_uuid); | ||
strncpy(obj_glob->name, obj->name, DFS_MAX_NAME + 1); | ||
obj_glob->name[DFS_MAX_NAME] = 0; | ||
/* DAOS-17042 Replace strncpy with strncat or strlcpy */ | ||
strncpy(obj_glob->name, obj->name, DFS_MAX_NAME); | ||
obj_glob->name[DFS_MAX_NAME] = '\0'; | ||
if (S_ISDIR(obj_glob->mode)) | ||
return 0; | ||
rc = dfs_get_chunk_size(obj, &obj_glob->chunk_size); | ||
|
@@ -674,7 +678,8 @@ dfs_obj_global2local(dfs_t *dfs, int flags, d_iov_t glob, dfs_obj_t **_obj) | |
|
||
oid_cp(&obj->oid, obj_glob->oid); | ||
oid_cp(&obj->parent_oid, obj_glob->parent_oid); | ||
strncpy(obj->name, obj_glob->name, DFS_MAX_NAME + 1); | ||
/* DAOS-17042 Replace strncpy with strncat or strlcpy */ | ||
strncpy(obj->name, obj_glob->name, DFS_MAX_NAME); | ||
obj->name[DFS_MAX_NAME] = '\0'; | ||
obj->mode = obj_glob->mode; | ||
obj->dfs = dfs; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove all these comments from the code. they are not helpful
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done