svn commit: samba r7025 - in branches/SAMBA_3_0/source: lib tdb

derrell at samba.org derrell at samba.org
Fri May 27 16:54:12 GMT 2005


This change to lib/util_sock.c that I checked in (r7025) should be sanity
checked.  I asked a few people to sanity check it a couple of weeks ago, but I
got feedback only from tridge.  I've been using this for a couple of weeks
with no problem, but since it is at the very core of samba functionality,
others should concur that it doesn't break anything.

derrell at samba.org writes:

>  
>  	if(len > 0) {
> -		ret = read_socket_data(fd,buffer+4,len);
> -		if (ret != len) {
> -			if (smb_read_error == 0)
> +                /*
> +                 * Read the remainder of the data.  Don't use a timeout since
> +                 * the overhead of it is not usually necessary.
> +                 */
> +                p = buffer + 4;         /* initial read buffer pointer */
> +                n_remaining = len;      /* initial length to be read */
> +                n_read = 0;             /* initialize number of bytes read */
> +
> +                ret = read_socket_data(fd, p, n_remaining);
> +
> +                if ((ret < 0 && errno == EAGAIN) ||
> +                    (ret > 0 && ret < n_remaining)) {
> +                        /*
> +                         * We were able to read the length earlier, but all of
> +                         * the remainder of the data is not yet available to
> +                         * us (as indicated by EAGAIN if we got nothing, or by
> +                         * the amount of just-read data not matching the
> +                         * packet length).  Read again, this time awaiting the
> +                         * data to arrive for a short period of time.
> +                         */
> +
> +                        /* If partial read occurred... */
> +                        if (ret > 0) {
> +                                /* ... then update buffer pointer and counts */
> +                                p += ret;
> +                                n_read += ret;
> +                                n_remaining -= ret;
> +                        }
> +
> +                        ret = read_socket_with_timeout(fd, p, n_remaining,
> +                                                       n_remaining, 20000);
> +                        if (ret > 0) {
> +                                n_read += ret;
> +                        }
> +                } else {
> +                        n_read = ret;
> +                }
> +
> +		if (n_read != len) {
> +			if (smb_read_error == 0) {
>  				smb_read_error = READ_ERROR;
> +                        }
>  			return False;
>  		}
>  		
> -		/* not all of samba3 properly checks for packet-termination of strings. This
> -		   ensures that we don't run off into empty space. */
> -		SSVAL(buffer+4,len, 0);
> +		/*
> +                 * not all of samba3 properly checks for packet-termination of
> +                 * strings. This ensures that we don't run off into empty
> +                 * space.
> +                 */
> +		SSVAL(buffer+4, len, 0);
>  	}
>  
>  	return True;


More information about the samba-cvs mailing list