Show entire path for checkpointing

Matthew Dillon dillon at apollo.backplane.com
Thu Jun 3 10:49:59 PDT 2004


:When a program is being checkpointed the checkpoint file is stored in the cwd
:for the program in question, which might be anything. So I have a patch here
:that instead of just showing the filename of the new checkpoint file, it also
:shows the path where it is stored.
:
:http://eirikn.kerneled.org/dragonfly/ckpt-show-entire-path.patch
:
:This patch depends on another patch I have here which separate the __getcwd
:function into a syscall part and a kernel part.
:
:http://eirikn.kerneled.org/dragonfly/split-getcwd-syscall.patch
:
:Any feedback would be great.
:
:-- 
:Eirik Nygaard
:eirikn at xxxxxxxxxxxx    Never let a computer know you're in a hurry.

    --- on the check point changes ---

    There is an overflow in temp when you added the '/'.  You are replacing
    the terminating \0 with '/' and not adding a new terminating \0, plus
    you may exceed the buffer size.  so instead of:

	if (ckptfilename[0] != '/') {
		if (kern_getcwd(temp, MAXPATHLEN) != 0) {  <<< SIZE OVERFLOW
			free(temp, M_TEMP);		     (due to append
			return NULL;			      below).
		}
		temp[strlen(temp)] = '/';	<<<< BAD
		n = strlen(temp);		<<<< BAD
	}

    do this:

	if (ckptfilename[0] != '/') {
		if (kern_getcwd(temp, MAXPATHLEN - 1) != 0) {
			free(temp, M_TEMP);
			return NULL;
		}
		n = strlen(temp);
		temp[n++] = '/';
		temp[n] = 0;
	}

    --- on the getcwd() changes ---

    #1: since the error path is so short, don't use a 'goto' in your
    __getcwd().  Just conditionalize the copyout.

    if (error == 0)
	    error = copyout(...)

    #2: Use bcopy() rather then strncpy() to copy-down the path at the end.
    strncpy() is not guarenteed to handle overlapping data.


    Otherwise it looks good and, with those changes, can be committed.

					-Matt
					Matthew Dillon 
					<dillon at xxxxxxxxxxxxx>





More information about the Kernel mailing list