From f4f54b1a8070f8725d5ed6f1dea21bf94554cc24 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 24 Jun 2019 11:02:42 +0530 Subject: [PATCH] Ensure that ensure_space does not leave a NULL pointer --- asan-launcher.c | 19 ----------------- kittens/choose/output.c | 2 +- kitty/launcher/kitty | 13 ------------ symlink-deref.c | 47 ----------------------------------------- 4 files changed, 1 insertion(+), 80 deletions(-) delete mode 100644 asan-launcher.c delete mode 100755 kitty/launcher/kitty delete mode 100644 symlink-deref.c diff --git a/asan-launcher.c b/asan-launcher.c deleted file mode 100644 index 6dc1bd5f02..0000000000 --- a/asan-launcher.c +++ /dev/null @@ -1,19 +0,0 @@ -/* - * asan-launcher.c - * Copyright (C) 2017 Kovid Goyal - * - * Distributed under terms of the GPL3 license. - */ - -#include - -#define MAX_ARGC 1024 - -int main(int argc, char *argv[]) { - wchar_t *argvw[MAX_ARGC + 1] = {0}; - argvw[0] = L"kitty"; - for (int i = 1; i < argc; i++) argvw[i] = Py_DecodeLocale(argv[i], NULL); - int ret = Py_Main(argc, argvw); - for (int i = 1; i < argc; i++) PyMem_RawFree(argvw[i]); - return ret; -} diff --git a/kittens/choose/output.c b/kittens/choose/output.c index eac45383ba..6dcf155060 100644 --- a/kittens/choose/output.c +++ b/kittens/choose/output.c @@ -25,7 +25,7 @@ static inline ssize_t ms_write(int fd, const void* buf, size_t count) { return _ static inline bool ensure_space(GlobalData *global, size_t sz) { - if (global->output_sz < sz + global->output_pos) { + if (global->output_sz < sz + global->output_pos || !global->output) { size_t before = global->output_sz; global->output_sz += MAX(sz, (64 * 1024)); global->output = realloc(global->output, sizeof(text_t) * global->output_sz); diff --git a/kitty/launcher/kitty b/kitty/launcher/kitty deleted file mode 100755 index b02eb9d707..0000000000 --- a/kitty/launcher/kitty +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env python3 -# vim:fileencoding=utf-8 -# License: GPL v3 Copyright: 2018, Kovid Goyal -# Launch kitty from source -import os -import sys - -base = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) -sys.path.insert(0, base) -with open(os.path.join(base, '__main__.py')) as f: - src = f.read() -code = compile(src, f.name, 'exec') -exec(code, {'__name__': '__main__'}) diff --git a/symlink-deref.c b/symlink-deref.c deleted file mode 100644 index 1bdf75e9f8..0000000000 --- a/symlink-deref.c +++ /dev/null @@ -1,47 +0,0 @@ -/* - * symlink-deref.c - * Copyright (C) 2019 Kovid Goyal - * - * Distributed under terms of the GPL3 license. - */ - - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static inline bool -safe_realpath(const char* src, char *buf, size_t buf_sz) { - char* ans = realpath(src, NULL); - if (ans == NULL) return false; - snprintf(buf, buf_sz, "%s", ans); - free(ans); - return true; -} - -static inline bool -read_exe_path(char *exe, size_t buf_sz) { - (void)buf_sz; - uint32_t size = PATH_MAX; - char apple[PATH_MAX+1] = {0}; - if (_NSGetExecutablePath(apple, &size) != 0) { fprintf(stderr, "Failed to get path to executable\n"); return false; } - if (!safe_realpath(apple, exe, buf_sz)) { fprintf(stderr, "realpath() failed on the executable's path\n"); return false; } - return true; -} - - -int -main(int argc, char *argv[]) { - char exe[PATH_MAX+1] = {0}; - char real_exe[PATH_MAX+1] = {0}; - if (!read_exe_path(exe, sizeof(exe))) return 1; - snprintf(real_exe, sizeof(real_exe), "%s/kitty", dirname(exe)); - return execv(real_exe, argv); -}