From edc3112679af749f0c6fc54b2eec1b89aaf0d0c8 Mon Sep 17 00:00:00 2001 From: Matthieu Herrb Date: Sun, 20 Apr 2008 17:30:14 +0200 Subject: Replace sprintf() and strcpy() with snprintf(). --- xinit.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/xinit.c b/xinit.c index 61cd378..d8e7c47 100644 --- a/xinit.c +++ b/xinit.c @@ -412,10 +412,11 @@ main(int argc, char *argv[], char *envp[]) xinitrcbuf[0] = '\0'; if ((cp = getenv ("XINITRC")) != NULL) { - strcpy (xinitrcbuf, cp); + (void) snprintf (xinitrcbuf, sizeof(xinitrcbuf), "%s", cp); required = True; } else if ((cp = getenv ("HOME")) != NULL) { - (void) sprintf (xinitrcbuf, "%s/%s", cp, XINITRC); + (void) snprintf (xinitrcbuf, sizeof(xinitrcbuf), + "%s/%s", cp, XINITRC); } if (xinitrcbuf[0]) { if (access (xinitrcbuf, F_OK) == 0) { @@ -439,10 +440,11 @@ main(int argc, char *argv[], char *envp[]) xserverrcbuf[0] = '\0'; if ((cp = getenv ("XSERVERRC")) != NULL) { - strcpy (xserverrcbuf, cp); + (void) snprintf (xserverrcbuf, sizeof(xserverrcbuf), "%s", cp); required = True; } else if ((cp = getenv ("HOME")) != NULL) { - (void) sprintf (xserverrcbuf, "%s/%s", cp, XSERVERRC); + (void) snprintf (xserverrcbuf, sizeof(xserverrcbuf), + "%s/%s", cp, XSERVERRC); } if (xserverrcbuf[0]) { if (access (xserverrcbuf, F_OK) == 0) { @@ -705,6 +707,7 @@ setWindowPath(void) unsigned long num; char nums[10]; int numn; + size_t len; prop = XInternAtom(xd, "XFree86_VT", False); if (prop == None) { #ifdef DEBUG @@ -760,11 +763,18 @@ setWindowPath(void) windowpath = getenv("WINDOWPATH"); numn = snprintf(nums, sizeof(nums), "%lu", num); if (!windowpath) { - newwindowpath = malloc(10 + 1 + numn + 1); - sprintf(newwindowpath, "WINDOWPATH=%s", nums); + len = 10 + 1 + numn + 1; + newwindowpath = malloc(len); + if (newwindowpath == NULL) + return; + snprintf(newwindowpath, len, "WINDOWPATH=%s", nums); } else { - newwindowpath = malloc(10 + 1 + strlen(windowpath) + 1 + numn + 1); - sprintf(newwindowpath, "WINDOWPATH=%s:%s", windowpath, nums); + len = 10 + 1 + strlen(windowpath) + 1 + numn + 1; + newwindowpath = malloc(len); + if (newwindowpath == NULL) + return; + snprintf(newwindowpath, len, "WINDOWPATH=%s:%s", + windowpath, nums); } *newenvironlast++ = newwindowpath; *newenvironlast = NULL; @@ -887,8 +897,7 @@ set_environment(void) } /* put DISPLAY=displayname as first element */ - strcpy (displaybuf, "DISPLAY="); - strcpy (displaybuf + 8, displayNum); + snprintf (displaybuf, sizeof(displaybuf), "DISPLAY=%s", displayNum); newPtr = newenviron; *newPtr++ = displaybuf; -- cgit v1.2.3