summaryrefslogtreecommitdiffstats
path: root/sysfs.c
diff options
context:
space:
mode:
authorMateusz Kusiak <mateusz.kusiak@intel.com>2024-01-18 11:28:40 +0100
committerMariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>2024-01-24 16:14:43 +0100
commit90fd70016b99e26e116b12246631b7d4aa3d3d08 (patch)
tree648a740ed3f7b338796a55f5f041f515b82875cb /sysfs.c
parenttests: Gate tests for linear flavor with variable LINEAR (diff)
downloadmdadm-90fd70016b99e26e116b12246631b7d4aa3d3d08.tar.xz
mdadm-90fd70016b99e26e116b12246631b7d4aa3d3d08.zip
Define sysfs max buffer size
sysfs_get_str() usages have inconsistant buffer size. This results in wild buffer declarations and redundant memory usage. Define maximum buffer size for sysfs strings. Replace wild sysfs string buffer sizes for globaly defined value. Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com> Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Diffstat (limited to '')
-rw-r--r--sysfs.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/sysfs.c b/sysfs.c
index decb02b8..0dc7badf 100644
--- a/sysfs.c
+++ b/sysfs.c
@@ -664,7 +664,7 @@ int sysfs_set_array(struct mdinfo *info, int vers)
ver[0] = 0;
if (info->array.major_version == -1 &&
info->array.minor_version == -2) {
- char buf[1024];
+ char buf[SYSFS_MAX_BUF_SIZE];
strcat(strcpy(ver, "external:"), info->text_version);
@@ -675,7 +675,7 @@ int sysfs_set_array(struct mdinfo *info, int vers)
* version first, and preserve the flag
*/
if (sysfs_get_str(info, NULL, "metadata_version",
- buf, 1024) > 0)
+ buf, sizeof(buf)) > 0)
if (strlen(buf) >= 9 && buf[9] == '-')
ver[9] = '-';
@@ -900,11 +900,11 @@ int sysfs_freeze_array(struct mdinfo *sra)
* return 0 if this kernel doesn't support 'frozen'
* return 1 if it worked.
*/
- char buf[20];
+ char buf[SYSFS_MAX_BUF_SIZE];
if (!sysfs_attribute_available(sra, NULL, "sync_action"))
return 1; /* no sync_action == frozen */
- if (sysfs_get_str(sra, NULL, "sync_action", buf, 20) <= 0)
+ if (sysfs_get_str(sra, NULL, "sync_action", buf, sizeof(buf)) <= 0)
return 0;
if (strcmp(buf, "frozen\n") == 0)
/* Already frozen */