diff -u old-xc/lib/X11/SetLocale.c xc/lib/X11/SetLocale.c
--- old-xc/lib/X11/SetLocale.c	Sat Sep 28 13:42:42 1996
+++ xc/lib/X11/SetLocale.c	Fri May 30 09:01:37 1997
@@ -63,6 +63,8 @@
 #include <X11/Xlocale.h>
 #include <X11/Xos.h>
 
+#define MAXLOCALE	64	/* buffer size of locale name */
+
 #ifdef X_LOCALE
 
 /* alternative setlocale() for when the OS does not provide one */
@@ -71,8 +73,6 @@
 extern char *getenv();
 #endif
 
-#define MAXLOCALE	64	/* buffer size of locale name */
-
 #if NeedFunctionPrototypes
 char *
 _Xsetlocale(
@@ -196,6 +196,8 @@
 #endif
 	if (end = strchr (start, ENDCHAR)) {
 	    len = end - start;
+	    if (len >= MAXLOCALE)
+		len = MAXLOCALE - 1;
 	    strncpy(siname, start, len);
 	    *(siname + len) = '\0';
 #ifdef WHITEFILL
@@ -209,7 +211,11 @@
     }
 #ifdef WHITEFILL
     if (strchr(osname, ' ')) {
-	strcpy(siname, osname);
+	len = strlen(osname);
+	if (len >= MAXLOCALE - 1)
+	    len = MAXLOCALE - 1;
+	strncpy(siname, osname, len);
+	*(siname + len) = '\0';
 	for (start = siname; start = strchr(start, ' '); )
 	    *start++ = '-';
 	return siname;
diff -u old-xc/lib/X11/Xrm.c xc/lib/X11/Xrm.c
--- old-xc/lib/X11/Xrm.c	Thu Jun  8 20:20:39 1995
+++ xc/lib/X11/Xrm.c	Thu May 29 14:07:49 1997
@@ -1179,10 +1179,11 @@
 	 * storing characters and converting this to a Quark.
 	 *
 	 * If the number of quarks is greater than LIST_SIZE - 1.  This
-	 * function will trash your memory.
+	 * function was able to trash your memory, so now checks for
+	 * boundaries added.
 	 *
 	 * If the length of any quark is larger than BUFSIZ this function
-	 * will also trash memory.
+	 * was also able to trash memory, so boundaries checks are added, too.
 	 */
 	
 	t_bindings = bindings;
@@ -1191,26 +1192,29 @@
 	sig = 0;
 	ptr = buffer;
 	*t_bindings = XrmBindTightly;	
-	for(;;) {
+	while(ptr - buffer < BUFSIZ && t_quarks - quarks < LIST_SIZE - 1) {
+
 	    if (!is_binding(bits)) {
-		while (!is_EOQ(bits)) {
+		while (!is_EOQ(bits) && (ptr - buffer < BUFSIZ)) {
 		    *ptr++ = c;
 		    sig = (sig << 1) + c; /* Compute the signature. */
 		    bits = next_char(c, str);
 		}
-
-		*t_quarks++ = _XrmInternalStringToQuark(buffer, ptr - buffer,
-							sig, False);
+		if(t_quarks-quarks < LIST_SIZE - 1)
+		    *t_quarks++ = _XrmInternalStringToQuark(buffer, ptr - buffer,
+							    sig, False);
 
 		if (is_separator(bits))  {
 		    if (!is_space(bits))
 			break;
 
 		    /* Remove white space */
-		    do {
-			*ptr++ = c;
-			sig = (sig << 1) + c; /* Compute the signature. */
-		    } while (is_space(bits = next_char(c, str)));
+		    if(ptr - buffer < BUFSIZ) {
+		        do {
+			    *ptr++ = c;
+			    sig = (sig << 1) + c; /* Compute the signature. */
+		        } while (is_space(bits = next_char(c, str)) && (ptr - buffer < BUFSIZ));
+	            }
 
 		    /* 
 		     * The spec doesn't permit it, but support spaces
@@ -1223,10 +1227,12 @@
 		    continue;
 		}
 
-		if (c == '.')
-		    *(++t_bindings) = XrmBindTightly;
-		else
-		    *(++t_bindings) = XrmBindLoosely;
+		if(t_bindings - bindings < LIST_SIZE - 1) {
+		    if (c == '.')
+		        *(++t_bindings) = XrmBindTightly;
+		    else
+		        *(++t_bindings) = XrmBindLoosely;
+		}
 
 		sig = 0;
 		ptr = buffer;
diff -u old-xc/lib/X11/lcFile.c xc/lib/X11/lcFile.c
--- old-xc/lib/X11/lcFile.c	Sat Sep 28 13:46:16 1996
+++ xc/lib/X11/lcFile.c	Fri May 30 09:09:02 1997
@@ -278,10 +278,22 @@
     }
 
     if(name != NULL){
-	strcpy(buf, name);
+	if(strlen(name) < BUFSIZE - 1){
+	    strcpy(buf, name);
+	}else{
+	    fprintf(stderr, "Warning: locale \"%s\" is too long, ignored\n",
+		    name);
+	    *buf = '\0';
+	}
 	Xfree(name);
     }else{
-	strcpy(buf, lc_name);
+	if(strlen(lc_name) < BUFSIZE - 1){
+	    strcpy(buf, lc_name);
+	}else{
+	    fprintf(stderr, "Warning: locale \"%s\" is too long, ignored\n",
+		    lc_name);
+	    *buf = '\0';
+	}
     }
     if(full_name != NULL){
 	strcpy(full_name, buf);
@@ -297,23 +309,54 @@
 	if(codeset) *codeset = '\0';
 
 	name_p = buf;
-	ptr = language;
-	while (1) {
-	    if (*name_p == '_') {
-		if (ptr)
-		    *ptr = '\0';
-		ptr = territory;
-	    } else if (*name_p == '.') {
-		if (ptr)
-		    *ptr = '\0';
-		ptr = codeset;
+	ptr = strchr(name_p, '_');
+	if (!ptr)
+	    ptr = strchr(name_p, '.');
+	if (!ptr)
+	    ptr = name_p + strlen(name_p);
+
+	/*
+	 * The size of the language, territory, codset buffers is 128 in
+	 * initialize() in lcPublic.c
+	 */
+	if (language) {
+	    if (ptr - name_p < 128) {
+	        strncpy(language, name_p, ptr - name_p);
+	        language[ptr - name_p] = '\0';
 	    } else {
-		if (ptr)
-		    *ptr++ = *name_p;
-		if (*name_p == '\0')
-		    break;
+	    fprintf(stderr,
+	    "Warning: language part of locale \"%s\" is too long, ignored\n",
+	    buf);
+	    }
+	}
+	if (*ptr == '_') {
+	    name_p = ptr + 1;
+	    ptr = strchr(name_p, '.');
+	    if (!ptr)
+		ptr = name_p + strlen(name_p);
+	    if (territory) {
+	        if (ptr - name_p < 128) {
+		    strncpy(territory, name_p, ptr - name_p);
+		    territory[ptr - name_p] = '\0';
+	    	} else {
+		fprintf(stderr,
+		"Warning: territory part of locale \"%s\" is too long, ignored\n",
+			buf);
+		}
+	    }
+	}
+	if (*ptr == '.') {
+	    name_p = ptr + 1;
+	    ptr = name_p + strlen(name_p);
+	    if (codeset){
+		if (ptr - name_p < 128) {
+			strcpy(codeset, name_p);
+	    	} else {
+		fprintf(stderr,
+		"Warning: codeset part of locale \"%s\" is too long, ignored\n",
+			buf);
+		}
 	    }
-	    name_p++;
 	}
     }
 
diff -u old-xc/lib/Xt/Initialize.c xc/lib/Xt/Initialize.c
--- old-xc/lib/Xt/Initialize.c	Wed Dec  4 07:25:29 1996
+++ xc/lib/Xt/Initialize.c	Sat May 31 02:14:53 1997
@@ -938,7 +938,9 @@
 		     argc_in_out, &argv_in_out, fallback_resources);
 
     LOCK_APP(app_con);
-    XtSetArg(args[num], XtNscreen, DefaultScreenOfDisplay(dpy)); num++;
+    if(dpy) {
+        XtSetArg(args[num], XtNscreen, DefaultScreenOfDisplay(dpy)); num++;
+     }
     XtSetArg(args[num], XtNargc, saved_argc);	                 num++;
     XtSetArg(args[num], XtNargv, argv_in_out);	                 num++;
 
diff -u old-xc/lib/Xt/Intrinsic.c xc/lib/Xt/Intrinsic.c
--- old-xc/lib/Xt/Intrinsic.c	Sat Sep 28 13:54:39 1996
+++ xc/lib/Xt/Intrinsic.c	Fri May 30 09:13:51 1997
@@ -1129,6 +1129,8 @@
 #endif
         if (end = strchr (start, ENDCHAR)) {
             len = end - start;
+	    if (len >= MAXLOCALE)
+		len = MAXLOCALE - 1;
             strncpy(buf, start, len);
             *(buf + len) = '\0';
 #ifdef WHITEFILL
@@ -1142,7 +1144,11 @@
     }
 #ifdef WHITEFILL
     if (strchr(lang, ' ')) {
-	strcpy(buf, lang);
+	len = strlen(lang);
+	if (len >= MAXLOCALE - 1)
+	    len = MAXLOCALE - 1;
+	strncpy(buf, lang, len);
+	*(buf + len) = '\0';
 	for (start = buf; start = strchr(start, ' '); )
 	    *start++ = '-';
 	return buf;
