Fix usage of xstrncpy
[sxemacs] / lib-src / gnuserv.c
index 3330e2a..05a33e9 100644 (file)
@@ -10,7 +10,7 @@
  Copyright (C) 1989 Free Software Foundation, Inc.
 
  Author: Andy Norman (ange@hplb.hpl.hp.com), based on 'etc/server.c'
-         from the 18.52 GNU Emacs distribution.
+        from the 18.52 GNU Emacs distribution.
 
  Please mail bugs and suggestions to the author at the above address.
 */
@@ -59,6 +59,13 @@ char gnuserv_version[] = "gnuserv version" GNUSERV_VERSION;
 #include <string.h>
 #endif                         /* HAVE_STRING_H */
 
+#define xstrncpy(d_,s_,l_)                     \
+       do {                                    \
+               char* dst_=d_;                  \
+               dst_[0]='\0';                   \
+               strncat((dst_),(s_),(l_)-1);    \
+       } while(0)
+
 
 #if !defined(SYSV_IPC) && !defined(UNIX_DOMAIN_SOCKETS) && \
     !defined(INTERNET_DOMAIN_SOCKETS)
@@ -186,9 +193,7 @@ handle_ipc_request(struct msgbuf *msgp)
        }
        /* if */
        msgctl(ipc_qid, IPC_STAT, &msg_st);
-       strncpy(buf, msgp->mtext, len);
-       /* terminate buf */
-       buf[len] = '\0';
+       xstrncpy(buf, msgp->mtext, sizeof(buf));
 
        printf("%d %s", ipc_qid, buf);
        fflush(stdout);
@@ -432,7 +437,7 @@ permitted(unsigned long host_addr, int fd)
                    strcmp(auth_protocol, MCOOKIE_NAME)) {
                        printf("authentication protocol (%s) \
 from client is invalid...\n\
-... Was the client an old version of gnuclient/gnudoit?\n", auth_protocol);
+... Was the client an old version of gnuclient?\n", auth_protocol);
                        return FALSE;
                }
 
@@ -677,7 +682,7 @@ handle_internet_request(int ls)
        /* Check that access is allowed - if not return crud to the client */
        if (!permitted(peer.sin_addr.s_addr, s)) {
                send_string(s, "\
-gnudoit: Connection refused\ngnudoit: unable to connect to remote");
+gnuclient: Connection refused\ngnuclient: unable to connect to remote");
                close(s);
 
                printf("Refused connection from %s\n",
@@ -787,6 +792,8 @@ handle_unix_request(int ls)
        if ((s = accept(ls, (struct sockaddr *)&server, &len)) < 0) {
                perror(progname);
                fprintf(stderr, "%s: unable to accept\n", progname);
+               /* Nothing more we can do here... */
+               return;
        }
        echo_request(s);
        return;