Skip to content

Commit cdfa130

Browse files
Reodushubcapsc
authored andcommitted
fs/orangefs: use snprintf() instead of sprintf()
sprintf() is discouraged for use with bounded destination buffers as it does not prevent buffer overflows when the formatted output exceeds the destination buffer size. snprintf() is a safer alternative as it limits the number of bytes written and ensures NUL-termination. Replace sprintf() with snprintf() for copying the debug string into a temporary buffer, using ORANGEFS_MAX_DEBUG_STRING_LEN as the maximum size to ensure safe formatting and prevent memory corruption in edge cases. EDIT: After this patch sat on linux-next for a few days, Dan Carpenter saw it and suggested that I use scnprintf instead of snprintf. I made the change and retested. Signed-off-by: Amir Mohammad Jahangirzad <[email protected]> Signed-off-by: Mike Marshall <[email protected]>
1 parent 347e9f5 commit cdfa130

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

fs/orangefs/orangefs-debugfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ static ssize_t orangefs_debug_read(struct file *file,
396396
goto out;
397397

398398
mutex_lock(&orangefs_debug_lock);
399-
sprintf_ret = sprintf(buf, "%s", (char *)file->private_data);
399+
sprintf_ret = scnprintf(buf, ORANGEFS_MAX_DEBUG_STRING_LEN, "%s", (char *)file->private_data);
400400
mutex_unlock(&orangefs_debug_lock);
401401

402402
read_ret = simple_read_from_buffer(ubuf, count, ppos, buf, sprintf_ret);

0 commit comments

Comments
 (0)