Whamcloud - gitweb
LU-2227 build: fix 'memory illegal access' errors
[fs/lustre-release.git] / lustre / lov / lov_pack.c
index 67c2188..c10d000 100644 (file)
@@ -142,6 +142,7 @@ int lov_packmd(struct obd_export *exp, struct lov_mds_md **lmmp,
         struct lov_ost_data_v1 *lmm_objects;
         int lmm_size, lmm_magic;
         int i;
+       int cplen = 0;
         ENTRY;
 
         if (lsm) {
@@ -226,8 +227,10 @@ int lov_packmd(struct obd_export *exp, struct lov_mds_md **lmmp,
         lmmv1->lmm_pattern = cpu_to_le32(lsm->lsm_pattern);
         lmmv1->lmm_layout_gen = cpu_to_le16(lsm->lsm_layout_gen);
         if (lsm->lsm_magic == LOV_MAGIC_V3) {
-                strncpy(lmmv3->lmm_pool_name, lsm->lsm_pool_name,
-                        LOV_MAXPOOLNAME);
+               cplen = strlcpy(lmmv3->lmm_pool_name, lsm->lsm_pool_name,
+                               sizeof(lmmv3->lmm_pool_name));
+               if (cplen >= sizeof(lmmv3->lmm_pool_name))
+                       RETURN(-E2BIG);
                 lmm_objects = lmmv3->lmm_objects;
         } else {
                 lmm_objects = lmmv1->lmm_objects;
@@ -413,6 +416,7 @@ static int __lov_setstripe(struct obd_export *exp, int max_lmm_size,
         int lmm_magic;
         __u16 stripe_count;
         int rc;
+       int cplen = 0;
         ENTRY;
 
         rc = lov_lum_swab_if_needed(lumv3, &lmm_magic, lump);
@@ -492,9 +496,13 @@ static int __lov_setstripe(struct obd_export *exp, int max_lmm_size,
         if (rc >= 0) {
                 (*lsmp)->lsm_oinfo[0]->loi_ost_idx = lumv1->lmm_stripe_offset;
                 (*lsmp)->lsm_stripe_size = lumv1->lmm_stripe_size;
-                if (lmm_magic == LOV_USER_MAGIC_V3)
-                        strncpy((*lsmp)->lsm_pool_name, lumv3->lmm_pool_name,
-                                LOV_MAXPOOLNAME);
+               if (lmm_magic == LOV_USER_MAGIC_V3) {
+                       cplen = strlcpy((*lsmp)->lsm_pool_name,
+                                       lumv3->lmm_pool_name,
+                                       sizeof((*lsmp)->lsm_pool_name));
+                       if (cplen >= sizeof((*lsmp)->lsm_pool_name))
+                               rc = -E2BIG;
+               }
                 rc = 0;
         }