[PATCH] fix pointer error in appl_head loadparm.c

Martin Pool mbp at samba.org
Fri Jan 17 05:20:59 GMT 2003


hp CR 1548

This patch fixes a problem I observed where there were error messages
relating to "getpwent /usr/bin/passwd", which is obviously a pretty
unlikely username.  Investigation showed that the problem comes from
the 1.247.2.52 patch to loadparm.c (appliance_head only), which
replaces some configuration parameters with two-entry arrays
containing both dos and unix values.  

The complicated macros for decoding these things has an error which
caused the array indexing to be carried out one level too high in the
tree of pointers.  (We got a[1][0] when we wanted a[0][1], basically.)
So the core change is 
 * (ptr[1]) 
into
 (* ptr)[1]

The attached patch is a minimally-intrusive attempt to fix this.  It
also removes some unncessary typecasts which might mask warnings
without apparently doing anything useful.  I have to say it still
looks pretty crufty, but I didn't want to risk a larger change, and in
any case this particular problem is only in appliance_head.

It seems that in the current code any caller to the lp_*_dos()
functions will get the wrong value!

Can somebody please review this?


--- loadparm.c.~1.247.2.54.~	2003-01-07 16:12:23.000000000 +1100
+++ loadparm.c	2003-01-17 15:46:36.000000000 +1100
@@ -1518,28 +1518,38 @@ static char *lp_string(const char *s, BO
 
 
 /*
-   In this section all the functions that are used to access the 
-   parameters from the rest of the program are defined 
+   In this section all the functions that are used to access the
+   parameters from the rest of the program are defined
 */
 
 #define FN_GLOBAL_STRING(fn_name,ptr) \
- char *fn_name(void) {return lp_string(*(char **)(ptr) ? *(char **)(ptr) : "",False);}
+ char *fn_name(void) {return lp_string(*(ptr) ? *(ptr) : "",False);}
+
 #define FN_GLOBAL_STRING_UNIX(fn_name,ptr) \
- char *fn_name(void) {return lp_string((*(char **)((ptr))[UNIX_STRING_OFFSET]) ? *(char **)((ptr)[UNIX_STRING_OFFSET]) : "", False);}
+ char *fn_name(void) {return lp_string((*(ptr))[UNIX_STRING_OFFSET] ? (* (ptr))[UNIX_STRING_OFFSET] : "", False);}
+
+/* ptr is a pointer to an array of 2 pointers to strings */
 #define FN_GLOBAL_STRING_DOS(fn_name,ptr) \
- char *fn_name(void) {return lp_string((*(char **)((ptr))[DOS_STRING_OFFSET]) ? *(char **)((ptr)[DOS_STRING_OFFSET]) : "", True);}
+ char *fn_name(void) {return lp_string((*(ptr))[DOS_STRING_OFFSET] ? (* (ptr))[DOS_STRING_OFFSET] : "", True);}
+
 #define FN_GLOBAL_CONST_STRING(fn_name,ptr) \
-const char *fn_name(void) {return(const char *)(*(char **)(ptr) ? *(char **)(ptr) : "");}
+const char *fn_name(void) {return (*(ptr) ? *(ptr) : "");}
+
 #define FN_GLOBAL_CONST_STRING_UNIX(fn_name,ptr) \
-const char *fn_name(void) {return(const char *)(*(char **)((ptr)[UNIX_STRING_OFFSET]) ? *(char **)((ptr)[UNIX_STRING_OFFSET]) : "");}
+const char *fn_name(void) {return (*(ptr))[UNIX_STRING_OFFSET] ? (*(ptr))[UNIX_STRING_OFFSET] : "";}
+
 #define FN_GLOBAL_CONST_STRING_DOS(fn_name,ptr) \
-const char *fn_name(void) {return(const char *)(*(char **)((ptr)[DOS_STRING_OFFSET]) ? *(char **)((ptr)[DOS_STRING_OFFSET]) : "");}
+const char *fn_name(void) {return (*(ptr))[DOS_STRING_OFFSET] ? (*(ptr))[DOS_STRING_OFFSET] : "";}
+
 #define FN_GLOBAL_LIST(fn_name,ptr) \
  char **fn_name(void) {return(*(char ***)(ptr));}
+
 #define FN_GLOBAL_BOOL(fn_name,ptr) \
  BOOL fn_name(void) {return(*(BOOL *)(ptr));}
+
 #define FN_GLOBAL_CHAR(fn_name,ptr) \
  char fn_name(void) {return(*(char *)(ptr));}
+
 #define FN_GLOBAL_INTEGER(fn_name,ptr) \
  int fn_name(void) {return(*(int *)(ptr));}
 


-- 
Martin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.samba.org/archive/samba-technical/attachments/20030117/a1955cc9/attachment.bin


More information about the samba-technical mailing list