Patch for OnUpdateBool in zend_ini.c

php.internals

Moriyoshi Koizumi

23 years ago
Hi, I just found OnUpdateBool ini handler is not working properly at the moment. <quote> ZEND_API ZEND_INI_MH(OnUpdateBool) { zend_bool *p; #ifndef ZTS char *base = (char *) mh_arg2; #else char *base; base = (char *) ts_resource(*((int *) mh_arg2)); #endif p = (zend_bool *) (base+(size_t) mh_arg1); if (strncasecmp("on", new_value, sizeof("on"))) { *p = (zend_bool) atoi(new_value); } else { *p = (zend_bool) 1; } return SUCCESS; } </quote> IMO, this part if (strncasecmp("on", new_value, sizeof("on"))) { *p = (zend_bool) atoi(new_value); } else { *p = (zend_bool) 1; } should be if (new_value_length == sizeof("on") -1 && strcasecmp("on", new_value) == 0) { *p = (zend_bool) 1; } else { *p = (zend_bool) atoi(new_value); } Otherwise you can set the corresponding entry to 1 if you specify a single letter "o" for it. The patch is attached. Moriyoshi

Zeev Suraski

23 years ago
At 16:27 12/05/2003, Moriyoshi Koizumi wrote:
>Hi, > >I just found OnUpdateBool ini handler is not working properly at the >moment. > ><quote> >ZEND_API ZEND_INI_MH(OnUpdateBool) >{ > zend_bool *p; >#ifndef ZTS > char *base = (char *) mh_arg2; >#else > char *base; > > base = (char *) ts_resource(*((int *) mh_arg2)); >#endif > > p = (zend_bool *) (base+(size_t) mh_arg1); > > if (strncasecmp("on", new_value, sizeof("on"))) { > *p = (zend_bool) atoi(new_value); > } else { > *p = (zend_bool) 1; > } > return SUCCESS; >} ></quote> > >IMO, this part > > if (strncasecmp("on", new_value, sizeof("on"))) { > *p = (zend_bool) atoi(new_value); > } else { > *p = (zend_bool) 1; > } > >should be > > if (new_value_length == sizeof("on") -1 && > strcasecmp("on", new_value) == 0) { > *p = (zend_bool) 1; > } else { > *p = (zend_bool) atoi(new_value); > } > >Otherwise you can set the corresponding entry to 1 if you specify >a single letter "o" for it.
Why? Does strncasecmp("on", "o", 2) return 0 on your system? Either way, I can't think of any reason not to simply replace strncasecmp with strcasecmp. The lengths should be identical either way. Zeev

Moriyoshi Koizumi

23 years ago
Zeev Suraski <zeev@zend.com> wrote:
> Why? Does strncasecmp("on", "o", 2) return 0 on your system? > Either way, I can't think of any reason not to simply replace strncasecmp > with strcasecmp. The lengths should be identical either way.
My bad... I might be confused. Please forget this. Moriyoshi

Rob Richards

23 years ago
Could someone take a look at this patch and commit it if no objections/issues. this should fix the last of the register_globals/bug_compat/bug_compat_warn issues. http://www.ctindustries.net/session.c.diff Tested in various scenarios and didn't have any problems. Thanks, Rob

Ken Tossell

23 years ago
Rob Richards wrote:
>Could someone take a look at this patch and commit it if no >objections/issues. >
i haven't tested it, but this is a great bug to fix. i remember having lots and lots of trouble with unset() -- nice work :)