diff --git a/ns/Cns_chmod.c b/ns/Cns_chmod.c index 49f6913dc04b1e1966dcbe98028760861f753b31..0a58f51a305fdd6be750ee3275651955b49346cf 100644 --- a/ns/Cns_chmod.c +++ b/ns/Cns_chmod.c @@ -45,7 +45,10 @@ Cns_chmod(const char *path, mode_t mode) return (-1); } - mode &= 07777; + if (mode > 4095) { + serrno = EINVAL; + return (-1); + } if (Cns_selectsrvr (path, thip->server, server, &actual_path)) return (-1); diff --git a/ns/Cns_mkdir.c b/ns/Cns_mkdir.c index 61ed80e2bd8c7e1448045378182c5f550ebc1823..c59b4752badd503a919efcd6465b21d9be49a398 100644 --- a/ns/Cns_mkdir.c +++ b/ns/Cns_mkdir.c @@ -49,7 +49,10 @@ Cns_mkdirg(const char *path, const char *guid, mode_t mode) return (-1); } - mode &= 07777; + if (mode > 4095) { + serrno = EINVAL; + return (-1); + } if (Cns_selectsrvr (path, thip->server, server, &actual_path)) return (-1); diff --git a/ns/Cns_procreq.c b/ns/Cns_procreq.c index 718e113d68f84936bcacd2d18f0e3bac6644447e..d564f33883e0e129dc75ecdfe67efa7823754969 100644 --- a/ns/Cns_procreq.c +++ b/ns/Cns_procreq.c @@ -389,6 +389,8 @@ int Cns_srv_chmod(char *req_data, if (unmarshall_STRINGN (rbp, path, CA_MAXPATHLEN+1)) RETURN (SENAMETOOLONG); unmarshall_LONG (rbp, mode); + /* mode must be within 0 and 07777 */ + if (mode > 4095) RETURN (EINVAL); /* Check if namespace is in 'readonly' mode */ if (rdonly) @@ -667,6 +669,8 @@ int Cns_srv_creat(int magic, if (unmarshall_STRINGN (rbp, path, CA_MAXPATHLEN+1)) RETURN (SENAMETOOLONG); unmarshall_LONG (rbp, mode); + /* mode must be within 0 and 07777 */ + if (mode > 4095) RETURN (EINVAL); if (magic >= CNS_MAGIC2) { if (unmarshall_STRINGN (rbp, guid, CA_MAXGUIDLEN+1)) RETURN (EINVAL); @@ -2365,6 +2369,8 @@ int Cns_srv_mkdir(int magic, if (unmarshall_STRINGN (rbp, path, CA_MAXPATHLEN+1)) RETURN (SENAMETOOLONG); unmarshall_LONG (rbp, mode); + /* mode must be within 0 and 07777 */ + if (mode > 4095) RETURN (EINVAL); if (magic >= CNS_MAGIC2) { if (unmarshall_STRINGN (rbp, guid, CA_MAXGUIDLEN+1)) RETURN (EINVAL); @@ -5840,6 +5846,8 @@ int Cns_srv_openx(char *req_data, unmarshall_LONG (rbp, flags); flags = ntohopnflg (flags); unmarshall_LONG (rbp, mode); + /* mode must be within 0 and 07777 */ + if (mode > 4095) RETURN (EINVAL); unmarshall_LONG (rbp, classid); /* Check if namespace is in 'readonly' mode */ diff --git a/ns/nsmkdir.c b/ns/nsmkdir.c index eb4e9f70e91af2c128b2fe9b589b2db3485d8f87..d6ca58c7c085cbd9251083782938ee05319ec5ae 100644 --- a/ns/nsmkdir.c +++ b/ns/nsmkdir.c @@ -63,7 +63,7 @@ int main(int argc, case 'm': mflag++; mode = strtol (Coptarg, &dp, 8); - if (*dp != '\0') { + if (*dp != '\0' || mode > 4095) { fprintf (stderr, "invalid value for option -m\n"); errflg++; }