diff options
author | Mihai Moldovan <ionic@ionic.de> | 2018-01-07 01:29:13 +0100 |
---|---|---|
committer | Mihai Moldovan <ionic@ionic.de> | 2018-01-07 01:29:13 +0100 |
commit | 5f9f744cd8497ac250717951512fa32d266a73a1 (patch) | |
tree | cb379a43f3775a032834cd816e6d41663970001c /nx-X11/programs/Xserver/hw/nxagent/Args.c | |
parent | 3c81899718e3429e45381beaaba58d4886a5537c (diff) | |
parent | 23c36c2d2c0d1ea85c1b638d71267c28522c08cd (diff) | |
download | nx-libs-5f9f744cd8497ac250717951512fa32d266a73a1.tar.gz nx-libs-5f9f744cd8497ac250717951512fa32d266a73a1.tar.bz2 nx-libs-5f9f744cd8497ac250717951512fa32d266a73a1.zip |
Merge branch 'uli42-pr/fix_strings' into 3.6.x
Attributes GH PR #567: https://github.com/ArcticaProject/nx-libs/pull/567
Diffstat (limited to 'nx-X11/programs/Xserver/hw/nxagent/Args.c')
-rw-r--r-- | nx-X11/programs/Xserver/hw/nxagent/Args.c | 120 |
1 files changed, 25 insertions, 95 deletions
diff --git a/nx-X11/programs/Xserver/hw/nxagent/Args.c b/nx-X11/programs/Xserver/hw/nxagent/Args.c index cccfd40e0..14f696e2d 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Args.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Args.c @@ -126,15 +126,15 @@ extern char dispatchExceptionAtReset; extern const char *__progname; -char nxagentDisplayName[1024]; +char nxagentDisplayName[NXAGENTDISPLAYNAMELENGTH]; Bool nxagentSynchronize = False; Bool nxagentRealWindowProp = False; -char nxagentShadowDisplayName[1024] = {0}; +char nxagentShadowDisplayName[NXAGENTSHADOWDISPLAYNAMELENGTH] = {0}; -char nxagentWindowName[256]; -char nxagentDialogName[256]; -char nxagentSessionId[256] = {0}; +char nxagentWindowName[NXAGENTWINDOWNAMELENGTH]; +char nxagentDialogName[NXAGENTDIALOGNAMELENGTH]; +char nxagentSessionId[NXAGENTSESSIONIDLENGTH] = {0}; char *nxagentOptionsFilenameOrString; Bool nxagentFullGeneration = False; @@ -215,14 +215,10 @@ int ddxProcessArgument(int argc, char *argv[], int i) { if ((!strcmp(argv[j], "-display")) && (j + 1 < argc)) { - envOptions = malloc(strlen(argv[j + 1]) + 1); + envOptions = strdup(argv[j + 1]); - if (envOptions != NULL) - { - envOptions = strcpy(envOptions, argv[j + 1]); - } #ifdef WARNING - else + if (envOptions == NULL) { fprintf(stderr, "ddxProcessArgument: WARNING! failed string allocation.\n"); } @@ -234,14 +230,10 @@ int ddxProcessArgument(int argc, char *argv[], int i) if ((envOptions == NULL) && (envDisplay != NULL)) { - envOptions = malloc(strlen(envDisplay) + 1); + envOptions = strdup(envDisplay); - if (envOptions != NULL) - { - envOptions = strcpy(envOptions, envDisplay); - } #ifdef WARNING - else + if (envOptions == NULL) { fprintf(stderr, "ddxProcessArgument: WARNING! failed string allocation.\n"); } @@ -326,10 +318,7 @@ int ddxProcessArgument(int argc, char *argv[], int i) { if (++i < argc) { - strncpy(nxagentDisplayName, argv[i], 1023); - - nxagentDisplayName[1023] = '\0'; - + snprintf(nxagentDisplayName, NXAGENTDISPLAYNAMELENGTH, "%s", argv[i]); return 2; } @@ -340,10 +329,7 @@ int ddxProcessArgument(int argc, char *argv[], int i) { if (++i < argc) { - strncpy(nxagentSessionId, argv[i], 255); - - *(nxagentSessionId + 255) = '\0'; - + snprintf(nxagentSessionId, NXAGENTSESSIONIDLENGTH, "%s", argv[i]); return 2; } @@ -360,35 +346,13 @@ int ddxProcessArgument(int argc, char *argv[], int i) { if (++i < argc) { - int size; - free(nxagentOptionsFilenameOrString); nxagentOptionsFilenameOrString = NULL; - if ((size = strlen(argv[i])) < 1024) - { - if ((nxagentOptionsFilenameOrString = malloc(size + 1)) == NULL) - { - FatalError("malloc failed"); - } - - strncpy(nxagentOptionsFilenameOrString, argv[i], size); - - nxagentOptionsFilenameOrString[size] = '\0'; - } - else + if (-1 == asprintf(&nxagentOptionsFilenameOrString, "%s", argv[i])) { - /* - * It is useless to store the file name - * that has just been truncated. - */ - - #ifdef WARNING - fprintf(stderr, "ddxProcessArgument: WARNING! Option file name " - "too long. It will be ignored.\n"); - #endif + FatalError("malloc failed"); } - return 2; } @@ -670,10 +634,7 @@ int ddxProcessArgument(int argc, char *argv[], int i) { if (++i < argc) { - strncpy(nxagentWindowName, argv[i], 255); - - *(nxagentWindowName + 255) = '\0'; - + snprintf(nxagentWindowName, NXAGENTWINDOWNAMELENGTH, "%s", argv[i]); return 2; } @@ -727,34 +688,14 @@ int ddxProcessArgument(int argc, char *argv[], int i) { if (++i < argc) { - int size; - free(nxagentKeyboard); nxagentKeyboard = NULL; - if ((size = strlen(argv[i])) < 256) - { - if ((nxagentKeyboard = malloc(size + 1)) == NULL) - { - FatalError("malloc failed"); - } - - strncpy(nxagentKeyboard, argv[i], size); - - nxagentKeyboard[size] = '\0'; - } - #ifdef WARNING - else + nxagentKeyboard = strdup(argv[i]); + if (nxagentKeyboard == NULL) { - /* - * it is useless to remember a kbtype - * option that has just been truncated. - */ - - fprintf(stderr, "ddxProcessArgument: WARNING! Option [%s] too long. " - "It will be ignored.\n", argv[i]); + FatalError("malloc failed"); } - #endif return 2; } @@ -903,15 +844,13 @@ int ddxProcessArgument(int argc, char *argv[], int i) { if (++i < argc) { - strncpy(nxagentShadowDisplayName, argv[i], 1023); + snprintf(nxagentShadowDisplayName, NXAGENTSHADOWDISPLAYNAMELENGTH, "%s", argv[i]); if (strcmp(nxagentShadowDisplayName, "") == 0) { FatalError("Invalid shadow display option"); } - *(nxagentShadowDisplayName + 1023) = '\0'; - return 2; } @@ -1315,7 +1254,7 @@ static void nxagentParseOptions(char *name, char *value) } else if (strcmp(name, "clients") == 0) { - strcpy(nxagentClientsLogName, value); + snprintf(nxagentClientsLogName, NXAGENTCLIENTSLOGNAMELENGTH, "%s", value); return; } @@ -1780,9 +1719,7 @@ N/A if (*nxagentWindowName == '\0') { - strncpy(nxagentWindowName, "NX", 255); - - *(nxagentWindowName + 255) = '\0'; + snprintf(nxagentWindowName, NXAGENTWINDOWNAMELENGTH, "NX"); } /* @@ -2161,31 +2098,24 @@ void ddxUseMsg() static int nxagentGetDialogName() { - strcpy(nxagentDialogName, "NX"); - - *(nxagentDialogName + 255) = '\0'; - if (*nxagentSessionId != '\0') { int length = strlen(nxagentSessionId); - strcpy(nxagentDialogName, "NX - "); - + /* if the session id contains an MD5 hash in a well-known format cut it off */ if (length > (MD5_LENGTH * 2 + 1) && *(nxagentSessionId + (length - (MD5_LENGTH * 2 + 1))) == '-') { - strncat(nxagentDialogName, nxagentSessionId, length - (MD5_LENGTH * 2 + 1)); - } - else - { - strncat(nxagentDialogName, nxagentSessionId, 250); + length -= (MD5_LENGTH * 2 + 1); } - *(nxagentSessionId + 255) = '\0'; + snprintf(nxagentDialogName, NXAGENTDIALOGNAMELENGTH, "NX - %.*s", length, nxagentSessionId); return 1; } + snprintf(nxagentDialogName, NXAGENTDIALOGNAMELENGTH, "NX"); + return 0; } |