From 7f39af86dd94f19e80af1861e8742e4a944deea3 Mon Sep 17 00:00:00 2001 From: "dmfreemon@users.noreply.github.com" Date: Sun, 15 Mar 2020 18:00:43 -0500 Subject: handle malloc() failures; use gnu_basename() instead of basenaem() --- src/firejail/x11.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/firejail/x11.c b/src/firejail/x11.c index 204889625..74de24b47 100644 --- a/src/firejail/x11.c +++ b/src/firejail/x11.c @@ -641,6 +641,10 @@ static char * get_title_arg_str() { if ((cfg.name != NULL) && (strlen(cfg.name) > 0)) { title_arg_str = malloc(strlen(title_start) + strlen(title_sep) + strlen(cfg.name) + 1); + if (title_arg_str == NULL) { + fprintf(stderr, "Error: malloc() failed to allocate memory\n"); + exit(1); + } strcpy(title_arg_str, title_start); strcat(title_arg_str, title_sep); @@ -650,10 +654,13 @@ static char * get_title_arg_str() { // use the "--private" argument if it was explicitly specified else if ((cfg.home_private != NULL) && (strlen(cfg.home_private) > 0)) { - char * tmp_in = strdupa(cfg.home_private); - char * base_out = strdupa(basename(tmp_in)); + const char * base_out = gnu_basename(cfg.home_private); title_arg_str = malloc(strlen(title_start) + strlen(title_sep) + strlen(base_out) + 1); + if (title_arg_str == NULL) { + fprintf(stderr, "Error: malloc() failed to allocate memory\n"); + exit(1); + } strcpy(title_arg_str, title_start); strcat(title_arg_str, title_sep); @@ -663,6 +670,10 @@ static char * get_title_arg_str() { // default else { title_arg_str = malloc(strlen(title_start) + 1); + if (title_arg_str == NULL) { + fprintf(stderr, "Error: malloc() failed to allocate memory\n"); + exit(1); + } strcpy(title_arg_str, title_start); } -- cgit v1.2.3-54-g00ecf