From 6e98e35cf24016c9789be26d33d918f6e0e3c9a1 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Thu, 28 Dec 2017 11:19:44 +0100 Subject: nxcomp: drop strncpy in favour of snprintf with very few exceptions which require careful thinking ;-) --- nxcomp/src/Children.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'nxcomp/src/Children.cpp') diff --git a/nxcomp/src/Children.cpp b/nxcomp/src/Children.cpp index 9486f189a..e586292da 100644 --- a/nxcomp/src/Children.cpp +++ b/nxcomp/src/Children.cpp @@ -275,12 +275,14 @@ int NXTransDialog(const char *caption, const char *message, #ifdef __APPLE__ + // FIXME: missing length limitation! strcat(newPath, "/Applications/NX Client for OSX.app/Contents/MacOS:"); #endif #ifdef __CYGWIN32__ + // FIXME: missing length limitation! strcat(newPath, ".:"); #endif @@ -289,9 +291,8 @@ int NXTransDialog(const char *caption, const char *message, char *oldPath = getenv("PATH"); - strncpy(newPath + newLength, oldPath, DEFAULT_STRING_LIMIT - newLength - 1); - - newPath[DEFAULT_STRING_LIMIT - 1] = '\0'; + // FIXME: check if strncat would be better here + snprintf(newPath + newLength, DEFAULT_STRING_LIMIT - newLength, "%s", oldPath); #ifdef WARNING *logofs << "NXTransDialog: WARNING! Trying with path '" @@ -427,17 +428,13 @@ int NXTransClient(const char* display) #ifdef __sun - snprintf(newDisplay, DISPLAY_LENGTH_LIMIT - 1, "DISPLAY=%s", display); - - newDisplay[DISPLAY_LENGTH_LIMIT - 1] = '\0'; + snprintf(newDisplay, DISPLAY_LENGTH_LIMIT, "DISPLAY=%s", display); putenv(newDisplay); #else - strncpy(newDisplay, display, DISPLAY_LENGTH_LIMIT - 1); - - newDisplay[DISPLAY_LENGTH_LIMIT - 1] = '\0'; + snprintf(newDisplay, DISPLAY_LENGTH_LIMIT, "%s", display); setenv("DISPLAY", newDisplay, 1); @@ -467,6 +464,7 @@ int NXTransClient(const char* display) if (i == 0) { + // FIXME: code dpulication: this whole block is duplicated in NXTransDialog strcpy(command, "nxclient"); char newPath[DEFAULT_STRING_LIMIT]; @@ -489,7 +487,8 @@ int NXTransClient(const char* display) char *oldPath = getenv("PATH"); - strncpy(newPath + newLength, oldPath, DEFAULT_STRING_LIMIT - newLength - 1); + // FIXME: check if strncat would be better here + snprintf(newPath + newLength, DEFAULT_STRING_LIMIT - newLength, "%s", oldPath); newPath[DEFAULT_STRING_LIMIT - 1] = '\0'; -- cgit v1.2.3