[gnu.emacs.bug] null ptr problem with 18.52 emacsclient.c

tony@UUNET.UU.NET (10/01/88)

Hello.

    Machine: 386 5.3

    I stumbled upon the fact there was support for SYSV IPC in emacsclient.c
    and tried turning it on.  It basically worked ok, but there was a problem
    where the path to be edited could have garbage inserted if the path given
    to emacsclient began with a '/'.  The diff below includes the following 
    changes:

    	-- would deref null ptr in cwd if path began w '/'
    	-- now only calls getcwd() once for all names
    	    	SYSV getcwd() spawns one or more sub-processes
    	-- minor changes to printfs ala the BSD section

    General comments:

    	I never saw any suggestion to consider turning on HAS_SYSVIPC in
    	any of the s- or m- files.  Should it be on by default in the 
    	SYSV s- files?

    	emacsclient/server usage is not documented anywhere (even in the src,
    	except in server.el)

    	I find it very useful, now that I [think i] understand it.

    	It would be nice if [on a non-windowing system], emacsclient could
    	"wake up" the emacs process and have it take over the screen once
    	again even if the invoking program wasn't an emacs process.  This 
    	would mean losing the screen contents of the pushed program, but 
    	would be somewhat more general.

--tony	 ...!uunet!h-three!tony	 (919) 549-8334	 h-three  Systems  Corporation
	 h-three!tony@uunet.uu.net		 POB 12557; RTP, NC 27709; USA
						 t. e. bennett


*** emacsclient.c~	Mon Sep 26 08:27:11 1988
--- emacsclient.c	Wed Sep 28 11:43:33 1988
***************
*** 142,148 ****
    int s;
    key_t key;
    struct msgbuf * msgp =
!       (struct msgbuf *) malloc (sizeof *msgp + BUFSIZ);
    struct msqid_ds * msg_st;
    char *homedir, *getenv (), buf[BUFSIZ];
    char *getwd (), *getcwd (), gwdirb[BUFSIZ], *cwd;
--- 142,148 ----
    int s;
    key_t key;
    struct msgbuf * msgp =
!       (struct msgbuf *) malloc (sizeof (long) + BUFSIZ);
    struct msqid_ds * msg_st;
    char *homedir, *getenv (), buf[BUFSIZ];
    char *getwd (), *getcwd (), gwdirb[BUFSIZ], *cwd;
***************
*** 171,199 ****
        exit (1);
      }
  
    msgp->mtext[0] = 0;
    argc--; argv++;
    while (argc)
      {
        if (*argv[0] != '/')
  	{
  	  char *val;
! 	  cwd = gwdirb; *cwd = '\0';
  #ifdef BSD
! 	  val = getwd (gwdirb);
  #else
! 	  val = getcwd (gwdirb, sizeof gwdirb);
  #endif
  
! 	  if (val != 0)
  	    {
! 	      strcat (cwd, "/");
  	    }
! 	  else
! 	    {
! 	      fprintf (stderr, cwd);
! 	      *cwd = '\0';
! 	    }
  	}
  	
        strcat (msgp->mtext, cwd);
--- 171,203 ----
        exit (1);
      }
  
+   cwd = gwdirb;
+   *cwd = '\0';
    msgp->mtext[0] = 0;
    argc--; argv++;
+ 
    while (argc)
      {
        if (*argv[0] != '/')
  	{
  	  char *val;
! 
!     	  if (*cwd == '\0')
!     	  {
  #ifdef BSD
! 	    val = getwd (gwdirb);
  #else
! 	    val = getcwd (gwdirb, sizeof gwdirb);
  #endif
  
! 	    if (val != 0)
! 	      	strcat (cwd, "/");
! 	    else
  	    {
! 	      	fprintf (stderr, cwd);
! 	      	*cwd = '\0';
  	    }
! 	  }
  	}
  	
        strcat (msgp->mtext, cwd);
***************
*** 212,223 ****
    /*
     * Now, wait for an answer
     */
!   printf ("Waiting\n");
  
    msgrcv (s, msgp, BUFSIZ, getpid (), 0);	/* wait for anything back */
    strcpy (buf, msgp->mtext);
  
!   printf ("Got back: %s\n", buf);
    exit (0);
  }
  
--- 216,228 ----
    /*
     * Now, wait for an answer
     */
!   printf ("Waiting for Emacs...");
!   fflush(stdout);
  
    msgrcv (s, msgp, BUFSIZ, getpid (), 0);	/* wait for anything back */
    strcpy (buf, msgp->mtext);
  
!   printf ("\n%s\n", buf);
    exit (0);
  }