update.
[chise/xemacs-chise.git.1] / lib-src / gnuclient.c
index 4ed986d..311249e 100644 (file)
@@ -198,7 +198,7 @@ filename_expand (char *fullpath, char *filename)
 #endif
 
   int len;
-  fullpath[0] = '\0';
+  fullpath[0] = fullpath[MAXPATHLEN] = '\0';
 
 #ifdef  CYGWIN
   /*
@@ -211,7 +211,7 @@ filename_expand (char *fullpath, char *filename)
   if (filename[0] && filename[0] == '/')
      {
        /* Absolute (unix-style) pathname.  Do nothing */
-       strcat (fullpath, filename);
+       strncat (fullpath, filename, MAXPATHLEN);
      }
   else
     {
@@ -219,15 +219,18 @@ filename_expand (char *fullpath, char *filename)
        and prepend it.  FIXME: need to fix the case of DOS paths like
        "\foo", where we need to get the current drive. */
 
-      strcat (fullpath, get_current_working_directory ());
+      strncat (fullpath, get_current_working_directory (), MAXPATHLEN);
       len = strlen (fullpath);
 
-      if (len > 0 && fullpath[len-1] == '/')   /* trailing slash already? */
-       ;                                       /* yep */
-      else
-       strcat (fullpath, "/");         /* nope, append trailing slash */
+      /* If no trailing slash, add one */
+      if (len <= 0 || (fullpath[len - 1] != '/' && len < MAXPATHLEN))
+       {
+         strcat (fullpath, "/");
+         len++;
+       }
+
       /* Don't forget to add the filename! */
-      strcat (fullpath,filename);
+      strncat (fullpath, filename, MAXPATHLEN - len);
     }
 } /* filename_expand */
 
@@ -329,11 +332,11 @@ main (int argc, char *argv[])
   char *remotearg;
   char thishost[HOSTNAMSZ];    /* this hostname */
   char remotepath[MAXPATHLEN+1]; /* remote pathname */
-  char *path;
   int rflg = 0;                        /* pathname given on cmdline */
   char *portarg;
   unsigned short port = 0;     /* port to server */
 #endif /* INTERNET_DOMAIN_SOCKETS */
+  char *path;                   /* used indiscriminately */
 #ifdef SYSV_IPC
   struct msgbuf *msgp;         /* message */
 #endif /* SYSV_IPC */
@@ -439,7 +442,7 @@ main (int argc, char *argv[])
                  break;
                case 'r':
                  GET_ARGUMENT (remotearg, "-r");
-                 strcpy (remotepath, remotearg);
+                 strncpy (remotepath, remotearg, MAXPATHLEN);
                  rflg = 1;
                  break;
 #endif /* INTERNET_DOMAIN_SOCKETS */
@@ -470,13 +473,14 @@ main (int argc, char *argv[])
               progname);
       exit (1);
     }
+#if defined(INTERNET_DOMAIN_SOCKETS)
   if (suppress_windows_system && hostarg)
     {
       fprintf (stderr, "%s: Remote editing is available only on X\n",
               progname);
       exit (1);
     }
-
+#endif
   *result = '\0';
   if (eval_function || eval_form || load_library)
     {
@@ -568,7 +572,7 @@ main (int argc, char *argv[])
            }
       /* Don't do disconnect_from_server because we have already read
         data, and disconnect doesn't do anything else. */
-#ifndef INTERNET_DOMAIN_SOCKETS
+#ifdef SYSV_IPC
          if (connect_type == (int) CONN_IPC)
            disconnect_from_ipc_server (s, msgp, FALSE);
 #endif /* !SYSV_IPC */
@@ -593,7 +597,7 @@ main (int argc, char *argv[])
                                         * to this machine */
              if ((ptr = getenv ("GNU_NODE")) != NULL)
                /* user specified a path */
-               strcpy (remotepath, ptr);
+               strncpy (remotepath, ptr, MAXPATHLEN);
            }
 #if 0  /* This is really bogus... re-enable it if you must have it! */
 #if defined (hp9000s300) || defined (hp9000s800)