summaryrefslogtreecommitdiffstats
path: root/api/src
diff options
context:
space:
mode:
authorSheetal Pamecha <spamecha@redhat.com>2019-08-19 15:27:57 +0530
committerAmar Tumballi <amarts@gmail.com>2019-09-12 08:02:34 +0000
commit61d438e73857776a1f96a7334f56b132275a587b (patch)
tree17f3fa5bb186097fd67dc21c2c1ba2e23e25dbab /api/src
parentda76f7bbef4d311775a5f75c96a54785170a1727 (diff)
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 <spamecha@redhat.com>
Diffstat (limited to 'api/src')
-rw-r--r--api/src/glfs.c15
1 files changed, 14 insertions, 1 deletions
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.