From ce43e4346fd8c4262f14b8abcddad209e021fbf1 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Sun, 29 Dec 2019 12:40:29 +0100 Subject: Dialog.c: fix format-truncation warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Dialog.c: In function ‘nxagentLaunchDialog’: Dialog.c:320:53: warning: ‘%s’ directive output may be truncated writing up to 1023 bytes into a region of size 256 [-Wformat-truncation=] snprintf(dialogDisplay, sizeof(dialogDisplay), "%s", nxagentDisplayName); ^~ ~~~~~~~~~~~~~~~~~~ Dialog.c:320:5: note: ‘snprintf’ output between 1 and 1024 bytes into a destination of size 256 snprintf(dialogDisplay, sizeof(dialogDisplay), "%s", nxagentDisplayName); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --- nx-X11/programs/Xserver/hw/nxagent/Dialog.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'nx-X11/programs/Xserver') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Dialog.c b/nx-X11/programs/Xserver/hw/nxagent/Dialog.c index c20a6a475..2d4eb6229 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Dialog.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Dialog.c @@ -40,6 +40,7 @@ #include "Args.h" #include "Display.h" #include "Dialog.h" +#include "Utils.h" #include #include "compext/Compext.h" @@ -182,7 +183,6 @@ void nxagentResetDialog(int pid) void nxagentLaunchDialog(DialogType dialogType) { - char dialogDisplay[256]; sigset_t set, oldSet; int *pid; char *type; @@ -302,13 +302,23 @@ void nxagentLaunchDialog(DialogType dialogType) fprintf(stderr, "nxagentLaunchDialog: Launching dialog type [%d] message [%s].\n", type, message); #endif + char *dialogDisplay = NULL; + int len = 0; if (dialogType == DIALOG_FAILED_RECONNECTION) { - snprintf(dialogDisplay, sizeof(dialogDisplay), "%s", nxagentDisplayName); + len = asprintf(&dialogDisplay, "%s", nxagentDisplayName); } else { - snprintf(dialogDisplay, sizeof(dialogDisplay), ":%s", display); + len = asprintf(&dialogDisplay, ":%s", display); + } + + if (len == -1) + { + #ifdef DEBUG + fprintf(stderr, "%s: could not allocate display string.\n", __func__); + #endif + return; } /* @@ -329,7 +339,7 @@ void nxagentLaunchDialog(DialogType dialogType) DECODE_DIALOG_TYPE(dialogType), *pid, dialogDisplay); #endif - dialogDisplay[0] = '\0'; + SAFE_free(dialogDisplay); /* * Restore the previous set of blocked signal. -- cgit v1.2.3