diff --git a/pkgs/tools/misc/tmux/CVE-2022-47016.patch b/pkgs/tools/misc/tmux/CVE-2022-47016.patch new file mode 100644 index 0000000000000..ae3d0f094b502 --- /dev/null +++ b/pkgs/tools/misc/tmux/CVE-2022-47016.patch @@ -0,0 +1,62 @@ +From e86752820993a00e3d28350cbe46878ba95d9012 Mon Sep 17 00:00:00 2001 +From: nicm +Date: Wed, 24 Aug 2022 07:22:30 +0000 +Subject: [PATCH] Check for NULL returns from bufferevent_new. + +diff --git a/control.c b/control.c +index 73286e00..6183a006 100644 +--- a/control.c ++++ b/control.c +@@ -775,6 +775,8 @@ control_start(struct client *c) + + cs->read_event = bufferevent_new(c->fd, control_read_callback, + control_write_callback, control_error_callback, c); ++ if (cs->read_event == NULL) ++ fatalx("out of memory"); + bufferevent_enable(cs->read_event, EV_READ); + + if (c->flags & CLIENT_CONTROLCONTROL) +@@ -782,6 +784,8 @@ control_start(struct client *c) + else { + cs->write_event = bufferevent_new(c->out_fd, NULL, + control_write_callback, control_error_callback, c); ++ if (cs->write_event == NULL) ++ fatalx("out of memory"); + } + bufferevent_setwatermark(cs->write_event, EV_WRITE, CONTROL_BUFFER_LOW, + 0); +diff --git a/file.c b/file.c +index b2f155fe..04a907bf 100644 +--- a/file.c ++++ b/file.c +@@ -585,6 +585,8 @@ file_write_open(struct client_files *files, struct tmuxpeer *peer, + + cf->event = bufferevent_new(cf->fd, NULL, file_write_callback, + file_write_error_callback, cf); ++ if (cf->event == NULL) ++ fatalx("out of memory"); + bufferevent_enable(cf->event, EV_WRITE); + goto reply; + +@@ -744,6 +746,8 @@ file_read_open(struct client_files *files, struct tmuxpeer *peer, + + cf->event = bufferevent_new(cf->fd, file_read_callback, NULL, + file_read_error_callback, cf); ++ if (cf->event == NULL) ++ fatalx("out of memory"); + bufferevent_enable(cf->event, EV_READ); + return; + +diff --git a/window.c b/window.c +index c0cd9bdc..294a1f08 100644 +--- a/window.c ++++ b/window.c +@@ -1042,6 +1042,8 @@ window_pane_set_event(struct window_pane *wp) + + wp->event = bufferevent_new(wp->fd, window_pane_read_callback, + NULL, window_pane_error_callback, wp); ++ if (wp->event == NULL) ++ fatalx("out of memory"); + wp->ictx = input_init(wp, wp->event, &wp->palette); + + bufferevent_enable(wp->event, EV_READ|EV_WRITE); diff --git a/pkgs/tools/misc/tmux/default.nix b/pkgs/tools/misc/tmux/default.nix index 139cadc70642c..38cc9f85b4413 100644 --- a/pkgs/tools/misc/tmux/default.nix +++ b/pkgs/tools/misc/tmux/default.nix @@ -1,14 +1,18 @@ -{ lib -, stdenv -, fetchFromGitHub -, autoreconfHook -, bison -, libevent -, ncurses -, pkg-config -, withSystemd ? lib.meta.availableOn stdenv.hostPlatform systemd, systemd -, withUtf8proc ? true, utf8proc # gets Unicode updates faster than glibc -, withUtempter ? stdenv.isLinux && !stdenv.hostPlatform.isMusl, libutempter +{ + lib, + stdenv, + fetchFromGitHub, + autoreconfHook, + bison, + libevent, + ncurses, + pkg-config, + withSystemd ? lib.meta.availableOn stdenv.hostPlatform systemd, + systemd, + withUtf8proc ? true, + utf8proc, # gets Unicode updates faster than glibc + withUtempter ? stdenv.isLinux && !stdenv.hostPlatform.isMusl, + libutempter, }: let @@ -26,7 +30,10 @@ stdenv.mkDerivation rec { pname = "tmux"; version = "3.3a"; - outputs = [ "out" "man" ]; + outputs = [ + "out" + "man" + ]; src = fetchFromGitHub { owner = "tmux"; @@ -35,6 +42,10 @@ stdenv.mkDerivation rec { sha256 = "sha256-SygHxTe7N4y7SdzKixPFQvqRRL57Fm8zWYHfTpW+yVY="; }; + patches = [ + ./CVE-2022-47016.patch + ]; + nativeBuildInputs = [ pkg-config autoreconfHook @@ -44,14 +55,16 @@ stdenv.mkDerivation rec { buildInputs = [ ncurses libevent - ] ++ lib.optionals withSystemd [ systemd ] + ] + ++ lib.optionals withSystemd [ systemd ] ++ lib.optionals withUtf8proc [ utf8proc ] ++ lib.optionals withUtempter [ libutempter ]; configureFlags = [ "--sysconfdir=/etc" "--localstatedir=/var" - ] ++ lib.optionals withSystemd [ "--enable-systemd" ] + ] + ++ lib.optionals withSystemd [ "--enable-systemd" ] ++ lib.optionals withUtempter [ "--enable-utempter" ] ++ lib.optionals withUtf8proc [ "--enable-utf8proc" ]; @@ -80,6 +93,11 @@ stdenv.mkDerivation rec { changelog = "https://github.com/tmux/tmux/raw/${version}/CHANGES"; license = lib.licenses.bsd3; platforms = lib.platforms.unix; - maintainers = with lib.maintainers; [ thammers fpletz SuperSandro2000 srapenne ]; + maintainers = with lib.maintainers; [ + thammers + fpletz + SuperSandro2000 + srapenne + ]; }; }