samba-2.0.0.beta4 : code optimisation in source/client/client.c

Pascal A. Dupuis dupuis at
Wed Dec 16 08:59:57 GMT 1998


I've already reported it, but it is still present in beta4 :

src/client/clinet.c : around line 1968, getenv() is called three times,
with the same argument. The glibc manual says the memory zone returned by
getenv() may be clobbered on non-glibc systems by other calls to getenv(), but 
there are no such calls in-between. I suggest to modify this code, in
order to avoid calling unneededly getenv : 

line 1924 new variable : char *p, *user; 

line 1968 : modify as:
if ((user=getenv("USER")) {
	pstrcpy(username, user);

        /* modification to support userid%passwd syntax in the USER var
                   25.Aug.97, jdblair at */
	if ((p=strchr(username,'%'))) {
                        *p = 0;
                        got_pass = True;
/* modification to support PASSWD environmental var
           25.Aug.97, jdblair at */
if ((user=getenv("PASSWD"))) {
                got_pass = True;
if ((user=getenv("PASSWD_FD")) {
        got_pass = True;
} else if ((user=getenv("PASSWD_FILE")) {
	got_pass = True;
if (*username == 0 && (user=getenv("LOGNAME"))) {

Also, I don't understand at all the goal of the memset at line 1978. In
the original version, it was :


thus :
  -get a fresh copy of the environment string "USER" (they are still two
       lying around)
  -search for the % delimiter
  -replace the password part by XXX	
You thus hide one copy in memory, what about the two others ?

Could you please tell me the purpose, or if I am wrong in my assumptions ?

Pascal A. Dupuis

linux : un noyau
windows : des pépins

More information about the samba-technical mailing list