From 19d3d95cb2364142d9d59d30cb62d8cb479a2b56 Mon Sep 17 00:00:00 2001 From: thantry Date: Thu, 14 Nov 2002 19:30:23 +0000 Subject: [PATCH] Bug Fix for Bug #369 --- lustre/ldlm/ldlm_resource.c | 5 ++--- lustre/llite/lproc_llite.c | 39 ++++++++++++++++++++++----------------- lustre/lov/lproc_lov.c | 2 +- lustre/obdclass/lprocfs_status.c | 15 ++++++++++----- 4 files changed, 35 insertions(+), 26 deletions(-) diff --git a/lustre/ldlm/ldlm_resource.c b/lustre/ldlm/ldlm_resource.c index 53b835a..bdb3449a 100644 --- a/lustre/ldlm/ldlm_resource.c +++ b/lustre/ldlm/ldlm_resource.c @@ -37,11 +37,10 @@ void ldlm_proc_cleanup(struct obd_device *obd) void ldlm_proc_namespace(struct ldlm_namespace *ns) { struct lprocfs_vars lock_vars[2]; - char lock_names[MAX_STRING_SIZE]; + char lock_names[MAX_STRING_SIZE+1]; memset(lock_vars, 0, sizeof(lock_vars)); - snprintf(lock_names, MAX_STRING_SIZE, "%s/resource_count", - ns->ns_name); + snprintf(lock_names, MAX_STRING_SIZE, "%s/resource_count", ns->ns_name); lock_names[MAX_STRING_SIZE] = '\0'; lock_vars[0].name = lock_names; lock_vars[0].read_fptr = lprocfs_ll_rd; diff --git a/lustre/llite/lproc_llite.c b/lustre/llite/lproc_llite.c index 0ccfb9c..1f51681 100644 --- a/lustre/llite/lproc_llite.c +++ b/lustre/llite/lproc_llite.c @@ -181,8 +181,8 @@ struct lprocfs_vars status_var_nm_1[] = { #define MAX_STRING_SIZE 100 void ll_proc_namespace(struct super_block* sb, char* osc, char* mdc) { - char mnt_name[MAX_STRING_SIZE]; - char uuid_name[MAX_STRING_SIZE]; + char mnt_name[MAX_STRING_SIZE+1]; + char uuid_name[MAX_STRING_SIZE+1]; struct lprocfs_vars d_vars[3]; struct ll_sb_info *sbi = ll_s2sbi(sb); struct obd_device* obd; @@ -190,44 +190,47 @@ void ll_proc_namespace(struct super_block* sb, char* osc, char* mdc) /* Register this mount instance with LProcFS */ - snprintf(mnt_name, 100, "mount_%s", sbi->ll_sb_uuid); + snprintf(mnt_name, MAX_STRING_SIZE, "mount_%s", sbi->ll_sb_uuid); + mnt_name[MAX_STRING_SIZE] = '\0'; sbi->ll_proc_root = lprocfs_reg_mnt(mnt_name); - if (!sbi->ll_proc_root) + if (sbi->ll_proc_root == NULL) { CDEBUG(D_OTHER, "Could not register FS"); + return; + } /* Add the static configuration info */ err = lprocfs_add_vars(sbi->ll_proc_root,status_var_nm_1, sb); - if (err) + if (err) { CDEBUG(D_OTHER, "Unable to add procfs variables\n"); - + return; + } /* MDC */ obd = class_uuid2obd(mdc); - - snprintf(mnt_name, MAX_STRING_SIZE, "status/%s/common_name", obd->obd_type->typ_name); - + mnt_name[MAX_STRING_SIZE] = '\0'; memset(d_vars, 0, sizeof(d_vars)); d_vars[0].read_fptr = rd_dev_name; d_vars[0].write_fptr = NULL; d_vars[0].name = mnt_name; - snprintf(uuid_name, MAX_STRING_SIZE, "status/%s/uuid", obd->obd_type->typ_name); + uuid_name[MAX_STRING_SIZE] = '\0'; d_vars[1].read_fptr = rd_dev_uuid; d_vars[1].write_fptr = NULL; d_vars[1].name = uuid_name; err = lprocfs_add_vars(sbi->ll_proc_root, d_vars, obd); - if (err) + if (err) { CDEBUG(D_OTHER, "Unable to add fs proc dynamic variables\n"); - + return; + } /* OSC or LOV*/ obd = class_uuid2obd(osc); /* Reuse mnt_name */ - snprintf(mnt_name, MAX_STRING_SIZE, "status/%s/common_name", - obd->obd_type->typ_name); - + snprintf(mnt_name, MAX_STRING_SIZE, + "status/%s/common_name", obd->obd_type->typ_name); + mnt_name[MAX_STRING_SIZE] = '\0'; memset(d_vars, 0, sizeof(d_vars)); d_vars[0].read_fptr = rd_dev_name; d_vars[0].write_fptr = NULL; @@ -235,13 +238,15 @@ void ll_proc_namespace(struct super_block* sb, char* osc, char* mdc) snprintf(uuid_name, MAX_STRING_SIZE, "status/%s/uuid", obd->obd_type->typ_name); + uuid_name[MAX_STRING_SIZE] = '\0'; d_vars[1].read_fptr = rd_dev_uuid; d_vars[1].write_fptr = NULL; d_vars[1].name = uuid_name; err = lprocfs_add_vars(sbi->ll_proc_root, d_vars, obd); - if (err) + if (err) { CDEBUG(D_OTHER, "Unable to add fs proc dynamic variables\n"); - + return; + } } #undef MAX_STRING_SIZE diff --git a/lustre/lov/lproc_lov.c b/lustre/lov/lproc_lov.c index 4845f41..a68b57e 100644 --- a/lustre/lov/lproc_lov.c +++ b/lustre/lov/lproc_lov.c @@ -154,7 +154,7 @@ int rd_target(char* page, char **start, off_t off, int count, int *eof, struct lov_obd* lov = &dev->u.lov; struct lov_tgt_desc* tgts = lov->tgts; while(i < lov->desc.ld_tgt_count){ - len += snprintf(page, count, "%d: %s\n", i, tgts->uuid); + len += snprintf(&page[len], count, "%d: %s\n", i, tgts->uuid); i++; tgts++; } diff --git a/lustre/obdclass/lprocfs_status.c b/lustre/obdclass/lprocfs_status.c index 1f8316c..62a806e 100644 --- a/lustre/obdclass/lprocfs_status.c +++ b/lustre/obdclass/lprocfs_status.c @@ -101,11 +101,11 @@ struct proc_dir_entry* lprocfs_new_dir(struct proc_dir_entry* root, { struct proc_dir_entry* new_root; struct proc_dir_entry* temp_entry; - char temp_string[MAX_STRING_SIZE]; + char temp_string[MAX_STRING_SIZE+1]; char* my_str; char* mover_str; - strncpy(temp_string, string, MAX_STRING_SIZE-1); + strncpy(temp_string, string, MAX_STRING_SIZE); temp_string[MAX_STRING_SIZE] = '\0'; new_root = root; @@ -138,7 +138,7 @@ int lprocfs_new_vars(struct proc_dir_entry* root, struct proc_dir_entry *temp_root; struct proc_dir_entry *new_leaf; struct proc_dir_entry *new_parent; - char temp_string[MAX_STRING_SIZE]; + char temp_string[MAX_STRING_SIZE+1]; if (list == NULL) return 0; @@ -147,16 +147,21 @@ int lprocfs_new_vars(struct proc_dir_entry* root, temp_root = lprocfs_new_dir(root, list->name, tok); if (temp_root == NULL) { CDEBUG(D_OTHER, "!LProcFS: Mods: No root!"); - return -EINVAL; + return -ENOMEM; } /* Convert the last element into a leaf-node */ - strncpy(temp_string, temp_root->name, MAX_STRING_SIZE-1); + strncpy(temp_string, temp_root->name, MAX_STRING_SIZE); temp_string[MAX_STRING_SIZE] = '\0'; new_parent = temp_root->parent; remove_proc_entry(temp_root->name, new_parent); new_leaf = create_proc_entry(temp_string, DEFAULT_MODE, new_parent); + if (new_leaf == NULL) { + CERROR("LprocFS: No memory to create /proc entry %s", + temp_string); + return -ENOMEM; + } new_leaf->read_proc = list->read_fptr; new_leaf->write_proc = list->write_fptr; if (data) -- 1.8.3.1