mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-18 02:25:18 +00:00
Remove last usage of PATH_MAX and ban its future use
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)
This commit is contained in:
parent
0f031d181f
commit
b4bbe640ef
5
cfg.mk
5
cfg.mk
@ -397,6 +397,11 @@ sc_prohibit_VIR_ERR_NO_MEMORY:
|
|||||||
halt='use virReportOOMError, not V'IR_ERR_NO_MEMORY \
|
halt='use virReportOOMError, not V'IR_ERR_NO_MEMORY \
|
||||||
$(_sc_search_regexp)
|
$(_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.
|
# Use a subshell for each function, to give the optimal warning message.
|
||||||
include $(srcdir)/Makefile.nonreentrant
|
include $(srcdir)/Makefile.nonreentrant
|
||||||
sc_prohibit_nonreentrant:
|
sc_prohibit_nonreentrant:
|
||||||
|
@ -473,7 +473,7 @@ valid_name(const char *name)
|
|||||||
* used to subvert the profile */
|
* used to subvert the profile */
|
||||||
const char *bad = " /[]*";
|
const char *bad = " /[]*";
|
||||||
|
|
||||||
if (strlen(name) == 0 || strlen(name) > PATH_MAX - 1)
|
if (strlen(name) == 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (strcspn(name, bad) != strlen(name))
|
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 */
|
"/sys/devices/pci" /* for hostdev pci devices */
|
||||||
};
|
};
|
||||||
|
|
||||||
if (path == NULL || strlen(path) > PATH_MAX - 1) {
|
if (path == NULL) {
|
||||||
vah_error(NULL, 0, _("bad pathname"));
|
vah_error(NULL, 0, _("bad pathname"));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -251,7 +251,7 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr pool,
|
|||||||
goto free_vol;
|
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") ||
|
||||||
STREQ(pool->def->target.path, "/dev/"))) {
|
STREQ(pool->def->target.path, "/dev/"))) {
|
||||||
|
|
||||||
|
@ -501,8 +501,6 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
|
|||||||
/* Extract the source file path*/
|
/* Extract the source file path*/
|
||||||
if (!(offset = strchr(head, ',')))
|
if (!(offset = strchr(head, ',')))
|
||||||
goto skipdisk;
|
goto skipdisk;
|
||||||
if ((offset - head) >= (PATH_MAX-1))
|
|
||||||
goto skipdisk;
|
|
||||||
|
|
||||||
if (offset == head) {
|
if (offset == head) {
|
||||||
disk->src = NULL; /* No source file given, eg CDROM with no media */
|
disk->src = NULL; /* No source file given, eg CDROM with no media */
|
||||||
|
@ -15229,11 +15229,12 @@ editWriteToTempFile (vshControl *ctl, const char *doc)
|
|||||||
const char *tmpdir;
|
const char *tmpdir;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
ret = vshMalloc(ctl, PATH_MAX);
|
|
||||||
|
|
||||||
tmpdir = getenv ("TMPDIR");
|
tmpdir = getenv ("TMPDIR");
|
||||||
if (!tmpdir) tmpdir = "/tmp";
|
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);
|
fd = mkstemps(ret, 4);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
vshError(ctl, _("mkstemps: failed to create temporary file: %s"),
|
vshError(ctl, _("mkstemps: failed to create temporary file: %s"),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user