]> sourceware.org Git - lvm2.git/commitdiff
Check result of dm_snprintf for error
authorZdenek Kabelac <zkabelac@redhat.com>
Wed, 5 Jan 2011 15:10:30 +0000 (15:10 +0000)
committerZdenek Kabelac <zkabelac@redhat.com>
Wed, 5 Jan 2011 15:10:30 +0000 (15:10 +0000)
lib/locking/cluster_locking.c
lib/locking/file_locking.c

index eea9974a33b95bb89c5c2596bd06b4b17ba49c66..8b7fe99989fdda4f5dc0824f9da7cf0916a24d09 100644 (file)
@@ -409,12 +409,14 @@ int lock_resource(struct cmd_context *cmd, const char *resource, uint32_t flags)
                }
 
                /* If the VG name is empty then lock the unused PVs */
-               if (is_orphan_vg(resource) || is_global_vg(resource) || (flags & LCK_CACHE))
-                       dm_snprintf(lockname, sizeof(lockname), "P_%s",
-                                   resource);
-               else
-                       dm_snprintf(lockname, sizeof(lockname), "V_%s",
-                                   resource);
+               if (dm_snprintf(lockname, sizeof(lockname), "%c_%s",
+                               (is_orphan_vg(resource) ||
+                                is_global_vg(resource) ||
+                                (flags & LCK_CACHE)) ?  'P' : 'V',
+                               resource)  < 0) {
+                       log_error("Locking resource %s too long.", resource);
+                       return 0;
+               }
 
                lock_scope = "VG";
                clvmd_cmd = CLVMD_CMD_LOCK_VG;
index 9137a30a51306fa93bf079249d073c93d50abeeb..d74bfd18553df9afaedfa9b4e4721f1c530bc86b 100644 (file)
@@ -268,12 +268,20 @@ static int _file_lock_resource(struct cmd_context *cmd, const char *resource,
                if (flags & LCK_CACHE)
                        break;
 
-               if (is_orphan_vg(resource) || is_global_vg(resource))
-                       dm_snprintf(lockfile, sizeof(lockfile),
-                                    "%s/P_%s", _lock_dir, resource + 1);
-               else
-                       dm_snprintf(lockfile, sizeof(lockfile),
-                                    "%s/V_%s", _lock_dir, resource);
+               if (is_orphan_vg(resource) || is_global_vg(resource)) {
+                       if (dm_snprintf(lockfile, sizeof(lockfile),
+                                       "%s/P_%s", _lock_dir, resource + 1) < 0) {
+                               log_error("Too long locking filename %s/P_%s.",
+                                         _lock_dir, resource + 1);
+                               return 0;
+                       }
+               } else
+                       if (dm_snprintf(lockfile, sizeof(lockfile),
+                                       "%s/V_%s", _lock_dir, resource) < 0) {
+                               log_error("Too long locking filename %s/V_%s.",
+                                         _lock_dir, resource);
+                               return 0;
+                       }
 
                if (!_lock_file(lockfile, flags))
                        return_0;
This page took 0.038995 seconds and 5 git commands to generate.