DragonFly BSD
DragonFly kernel List (threaded) for 2004-06
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Re: Show entire path for checkpointing

From: Matthew Dillon <dillon@xxxxxxxxxxxxxxxxxxxx>
Date: Thu, 3 Jun 2004 10:47:43 -0700 (PDT)

: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.
:This patch depends on another patch I have here which separate the __getcwd
:function into a syscall part and a kernel part.
:Any feedback would be great.
:Eirik Nygaard
:eirikn@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.

					Matthew Dillon 

[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]