]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Remove last usage of PATH_MAX and ban its future use
authorDaniel P. Berrange <berrange@redhat.com>
Fri, 25 May 2012 13:14:07 +0000 (14:14 +0100)
committerCole Robinson <crobinso@redhat.com>
Thu, 14 Jun 2012 22:22:52 +0000 (18:22 -0400)
Remove a number of pointless checks against PATH_MAX and
add a syntax-check rule to prevent its use in future

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
(cherry picked from commit ebbcc0263969cc4472f4aafea8901154c790a196)

cfg.mk
src/security/virt-aa-helper.c
src/storage/storage_backend_scsi.c
src/xenxs/xen_xm.c
tools/virsh.c

diff --git a/cfg.mk b/cfg.mk
index b517e7ccb2ccb2164ea29fe8493f2b3c8e093605..61a82f4913d44f730de706ce5d3b7c05d743e3d7 100644 (file)
--- a/cfg.mk
+++ b/cfg.mk
@@ -397,6 +397,11 @@ sc_prohibit_VIR_ERR_NO_MEMORY:
        halt='use virReportOOMError, not V'IR_ERR_NO_MEMORY             \
          $(_sc_search_regexp)
 
+sc_prohibit_PATH_MAX:
+       @prohibit='\<P''ATH_MAX\>'                              \
+       halt='dynamically allocate paths, do not use P'ATH_MAX  \
+         $(_sc_search_regexp)
+
 # Use a subshell for each function, to give the optimal warning message.
 include $(srcdir)/Makefile.nonreentrant
 sc_prohibit_nonreentrant:
index a5cb85c830b54687618e35624e5fd3d7c901d554..7b41d38498308eb8115e4b1bf5d8dba14ff6d596 100644 (file)
@@ -473,7 +473,7 @@ valid_name(const char *name)
      * used to subvert the profile */
     const char *bad = " /[]*";
 
-    if (strlen(name) == 0 || strlen(name) > PATH_MAX - 1)
+    if (strlen(name) == 0)
         return -1;
 
     if (strcspn(name, bad) != strlen(name))
@@ -544,7 +544,7 @@ valid_path(const char *path, const bool readonly)
         "/sys/devices/pci"     /* for hostdev pci devices */
     };
 
-    if (path == NULL || strlen(path) > PATH_MAX - 1) {
+    if (path == NULL) {
         vah_error(NULL, 0, _("bad pathname"));
         return -1;
     }
index ae1e19f8ef522fbade8cad6778510527aad380ff..465d5570ae9bc6dc690f1254a337fa092f976d77 100644 (file)
@@ -251,7 +251,7 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr pool,
         goto free_vol;
     }
 
-    if (STREQLEN(devpath, vol->target.path, PATH_MAX) &&
+    if (STREQ(devpath, vol->target.path) &&
         !(STREQ(pool->def->target.path, "/dev") ||
           STREQ(pool->def->target.path, "/dev/"))) {
 
index 93a26f90d136610fe91112c06436a6152c21c678..bdf46bdf52589cb2be71d3ded4aad9170ab54fda 100644 (file)
@@ -501,8 +501,6 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
             /* Extract the source file path*/
             if (!(offset = strchr(head, ',')))
                 goto skipdisk;
-            if ((offset - head) >= (PATH_MAX-1))
-                goto skipdisk;
 
             if (offset == head) {
                 disk->src = NULL; /* No source file given, eg CDROM with no media */
index 3c19346fc44492978a7c878a4b9e3d5ff4fdbe6a..bd84fab7c70f9c3c69e16bbdf575a789bfd006d5 100644 (file)
@@ -15229,11 +15229,12 @@ editWriteToTempFile (vshControl *ctl, const char *doc)
     const char *tmpdir;
     int fd;
 
-    ret = vshMalloc(ctl, PATH_MAX);
-
     tmpdir = getenv ("TMPDIR");
     if (!tmpdir) tmpdir = "/tmp";
-    snprintf (ret, PATH_MAX, "%s/virshXXXXXX.xml", tmpdir);
+    if (virAsprintf(&ret, "%s/virshXXXXXX.xml", tmpdir) < 0) {
+        vshError(ctl, "%s", _("out of memory"));
+        return NULL;
+    }
     fd = mkstemps(ret, 4);
     if (fd == -1) {
         vshError(ctl, _("mkstemps: failed to create temporary file: %s"),