From 4e7418f2f16bf88af4642c11d5d97b2be71d7380 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 24 Apr 2025 21:51:46 +0530 Subject: [PATCH] Have makedirs operate on abspaths clean() wont work with paths that use .. to go to levels above the root of the passed in path. --- kitty/data-types.c | 7 +++---- kitty/launcher/utils.h | 7 ++++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/kitty/data-types.c b/kitty/data-types.c index 285abba50..9172f319d 100644 --- a/kitty/data-types.c +++ b/kitty/data-types.c @@ -654,10 +654,9 @@ abspath(PyObject *self UNUSED, PyObject *path) { static PyObject* py_makedirs(PyObject *self UNUSED, PyObject *args) { - int mode = 0755; const char *p; Py_ssize_t sz; - if (!PyArg_ParseTuple(args, "s#|i", &p, &sz, &mode)) return NULL; - RAII_PyObject(b, PyBytes_FromStringAndSize(p, sz)); - if (!makedirs(PyBytes_AS_STRING(b), mode)) { PyErr_SetFromErrno(PyExc_OSError); return NULL; } + int mode = 0755; const char *p; + if (!PyArg_ParseTuple(args, "s|i", &p, &mode)) return NULL; + if (!makedirs(p, mode)) { PyErr_SetFromErrno(PyExc_OSError); return NULL; } Py_RETURN_NONE; } diff --git a/kitty/launcher/utils.h b/kitty/launcher/utils.h index 6c1ebe57c..ae07c2323 100644 --- a/kitty/launcher/utils.h +++ b/kitty/launcher/utils.h @@ -145,10 +145,11 @@ makedirs_cleaned(char *path, int mode, struct stat *buffer) { } static bool -makedirs(char *path /* path is modified by this function */, int mode) { +makedirs(const char *path, int mode) { struct stat buffer; - clean_path(path); - return makedirs_cleaned(path, mode, &buffer); + char pbuf[PATH_MAX]; + lexical_absolute_path(path, pbuf, sizeof(pbuf)); + return makedirs_cleaned(pbuf, mode, &buffer); } static bool