D7105: dirs: reject consecutive slashes in paths
Yuya Nishihara
yuya at tcha.org
Wed Oct 16 08:23:32 EDT 2019
> 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.
More information about the Mercurial-devel
mailing list