Patchwork D7105: dirs: reject consecutive slashes in paths

login
register
mail settings
Submitter phabricator
Date Oct. 16, 2019, 4:08 a.m.
Message ID <8acdcf26944c47ae3e95925ad1fe5aca@localhost.localdomain>
Download mbox | patch
Permalink /patch/42376/
State Not Applicable
Headers show

Comments

phabricator - Oct. 16, 2019, 4:08 a.m.
Closed by commit rHG1f04c51d52ea: dirs: reject consecutive slashes in paths (authored by durin42).
This revision was automatically updated to reflect the committed changes.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7105?vs=17173&id=17192

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7105/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7105

AFFECTED FILES
  mercurial/cext/dirs.c

CHANGE DETAILS




To: durin42, #hg-reviewers, indygreg
Cc: indygreg, mercurial-devel
Yuya Nishihara - Oct. 16, 2019, 12:23 p.m.
> diff --git a/mercurial/cext/dirs.c b/mercurial/cext/dirs.c
> --- a/mercurial/cext/dirs.c
> +++ b/mercurial/cext/dirs.c
> @@ -52,6 +52,7 @@
>  {
>  	const char *cpath = PyBytes_AS_STRING(path);
>  	Py_ssize_t pos = PyBytes_GET_SIZE(path);
> +	Py_ssize_t prev_pos = -1;
>  	PyObject *key = NULL;
>  	int ret = -1;
>  
> @@ -64,6 +65,13 @@
>  	 * locations, the references are known so these violations should go
>  	 * unnoticed. */
>  	while ((pos = _finddir(cpath, pos - 1)) != -1) {
> +		if (pos && prev_pos == pos + 1) {

Maybe it's better to reject leading "/" and trailing "/".

> +			PyErr_SetString(
> +			    PyExc_ValueError,
> +			    "invalid empty directory name in dirs.c _addpath");
> +			return -1;

`goto bail;` is the way to error out from this function, though it doesn't
matter here.
phabricator - Oct. 16, 2019, 12:25 p.m.
yuja added a comment.


  > diff --git a/mercurial/cext/dirs.c b/mercurial/cext/dirs.c
  >
  > - a/mercurial/cext/dirs.c
  >
  > +++ b/mercurial/cext/dirs.c
  > @@ -52,6 +52,7 @@
  >  {
  >
  >   	const char *cpath = PyBytes_AS_STRING(path);
  >   	Py_ssize_t pos = PyBytes_GET_SIZE(path);
  >
  > +	Py_ssize_t prev_pos = -1;
  >
  >   	PyObject *key = NULL;
  >   	int ret = -1;
  >
  > @@ -64,6 +65,13 @@
  >
  > - locations, the references are known so these violations should go
  > - unnoticed. */ 	while ((pos = _finddir(cpath, pos - 1)) != -1) {
  >
  > +		if (pos && prev_pos == pos + 1) {
  
  Maybe it's better to reject leading "/" and trailing "/".
  
  > +			PyErr_SetString(
  > +			    PyExc_ValueError,
  > +			    "invalid empty directory name in dirs.c _addpath");
  > +			return -1;
  
  `goto bail;` is the way to error out from this function, though it doesn't
  matter here.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7105/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7105

To: durin42, #hg-reviewers, indygreg
Cc: yuja, indygreg, mercurial-devel

Patch

diff --git a/mercurial/cext/dirs.c b/mercurial/cext/dirs.c
--- a/mercurial/cext/dirs.c
+++ b/mercurial/cext/dirs.c
@@ -52,6 +52,7 @@ 
 {
 	const char *cpath = PyBytes_AS_STRING(path);
 	Py_ssize_t pos = PyBytes_GET_SIZE(path);
+	Py_ssize_t prev_pos = -1;
 	PyObject *key = NULL;
 	int ret = -1;
 
@@ -64,6 +65,13 @@ 
 	 * locations, the references are known so these violations should go
 	 * unnoticed. */
 	while ((pos = _finddir(cpath, pos - 1)) != -1) {
+		if (pos && prev_pos == pos + 1) {
+			PyErr_SetString(
+			    PyExc_ValueError,
+			    "invalid empty directory name in dirs.c _addpath");
+			return -1;
+		}
+		prev_pos = pos;
 		PyObject *val;
 
 		key = PyBytes_FromStringAndSize(cpath, pos);