From 61d438e73857776a1f96a7334f56b132275a587b Mon Sep 17 00:00:00 2001 From: Sheetal Pamecha Date: Mon, 19 Aug 2019 15:27:57 +0530 Subject: libgfapi: return correct errno on invalid volume name glfs_init when called with volume name prefixed by '/' sets errno to 0. Setting errno to EINVAL to resolve the issue. Also volname is a parameter to glfs_new. Thus, validating volname in glfs_new itself and returning EINVAL from that function fixes: bz#1507896 Change-Id: I0d4d2423e26cc07644d50ec8cce788ecc639203d Signed-off-by: Sheetal Pamecha --- api/src/glfs.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'api') diff --git a/api/src/glfs.c b/api/src/glfs.c index 3f9622eea5d..82261369fe1 100644 --- a/api/src/glfs.c +++ b/api/src/glfs.c @@ -817,17 +817,30 @@ struct glfs * pub_glfs_new(const char *volname) { struct glfs *fs = NULL; + int i = 0; int ret = -1; glusterfs_ctx_t *ctx = NULL; xlator_t *old_THIS = NULL; char pname[16] = ""; char msg[32] = ""; - if (!volname) { + if (!volname || volname[0] == '/' || volname[0] == '-') { + if (strncmp(volname, "/snaps/", 7) == 0) { + goto label; + } errno = EINVAL; return NULL; } + for (i = 0; i < strlen(volname); i++) { + if (!isalnum(volname[i]) && (volname[i] != '_') && + (volname[i] != '-')) { + errno = EINVAL; + return NULL; + } + } + +label: /* * Do this as soon as possible in case something else depends on * pool allocations. -- cgit