[vchkpw] Solved: Re: Runtime error

2013-06-13 Thread Allan Dukat
Hi list 

I have had some help from a colleague, so now my problem is solved :-) 

When a Dir do not hold any forwards, then num_names equals 0 in vpalias.c 
at line 372, realloc will call free in order to assign 0 bytes for names, 
and return NULL for success. 

When valias_select_names_end free names a double free error occurred, 
generates the behavior described below. 


The following output from
"diff -Naur vpopmail-5.4.33/vpalias.c new/vpalias.c"
show the changes I've made in order to get it to work: 



--- vpopmail-5.4.33/vpalias.c   2011-02-28 18:00:45.0 +0100
+++ new/vpalias.c   2013-06-13 16:10:49.269063043 +0200
@@ -315,6 +315,9 @@
num_names = 0;

names = malloc( max_names * sizeof(char *));
+if (names == NULL) {
+  return(NULL);
+}
memset(names, 0, max_names * sizeof(char *));

if ( (mydir = opendir(Dir)) == NULL ) return(NULL);
@@ -348,6 +351,10 @@
  for(i = 0; i < num_names; i++)
free(names[i]);
  free(names);
+ names=NULL;
+ max_names=0;
+ num_names=0;
+ cur_name=0;
  return(NULL);
}

@@ -369,11 +376,6 @@
}
  }
}
-if (num_names < max_names) {
-  new_names = realloc( names, num_names * sizeof(char *) );
-  if (new_names != NULL)
-   names = new_names;
-}

if (mydir!=NULL) {
  closedir(mydir); 



If I have to contribute the patch in any other way, please let me know. 


Best regards,
Allan Dukat 



Allan Dukat writes: 

Hi list  

I have a problem with qmailadmin-1.2.16, configured like this:  


./configure \
--enable-vpopmaildir=/home/vpopmail \
--enable-htmldir=/usr/local/apache2/htdocs \
--enable-cgibindir=/usr/local/apache2/cgi-bin \
--enable-imageurl=/images/qmailadmin \
--enable-imagedir=/usr/local/apache2/htdocs/images/qmailadmin \
--enable-qmaildir=/var/qmail \
--enable-ezmlmdir=/usr/local/bin/ezmlm \
--enable-cgipath=/cgi-bin/qmailadmin \
--enable-autoresponder-path=/usr/local/bin \
--enable-vpopuser=vpopmail \
--enable-vpopgroup=vchkpw \
--disable-ezmlm-mysql \
--enable-modify-quota \
--enable-help  


When adding the fist Forward I got an empty page as answer, an this in
Apache errorlog:  

*** glibc detected *** /usr/local/apache2/cgi-bin/qmailadmin: double free 
or corruption (top): 0x01f326e0 ***

=== Backtrace: =
/lib/x86_64-linux-gnu/libc.so.6(+0x7eb96)[0x7f9ed7c8ab96]
/usr/local/apache2/cgi-bin/qmailadmin[0x421f04]
/usr/local/apache2/cgi-bin/qmailadmin[0x4219ad]
/usr/local/apache2/cgi-bin/qmailadmin[0x42202f]
/usr/local/apache2/cgi-bin/qmailadmin[0x40715d]
/usr/local/apache2/cgi-bin/qmailadmin[0x4070a3]
/usr/local/apache2/cgi-bin/qmailadmin[0x4054f5]
/usr/local/apache2/cgi-bin/qmailadmin[0x4130c3]
/usr/local/apache2/cgi-bin/qmailadmin[0x402db6]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xed)[0x7f9ed7c2d76d]
/usr/local/apache2/cgi-bin/qmailadmin[0x402929] 



The Forward is added, and I can add and list Forwards from now on. When
all Forward is deleted and I add a new Forward the error is repeated with
the same addresses. 



Best regards,
Allan Dukat


!DSPAM:51b9dfc834132014110541!



Re: [vchkpw] Re: Runtime error

2013-06-13 Thread Welinton


Allan Dukat  escreveu:

>Hello everyone on this list. 
>
>If I comment out the free-lines in in valias_select_names_end in vpalias.c, 
>like this: 
>
>void valias_select_names_end()
>{
> int i; 
>
>  /* if( NULL != names ) {
>for(i=0;i  free(names[i]);
>}
>free(names);
>names=NULL;
>  } */
>  max_names=0;
>  num_names=0;
>  cur_name=0;
>} 
>
>qmaildmin runs without any error. 
>
>Why is it needed to free the memory, is it not so that Apache will do a 
>proper clean up when the request ends anyway? 
>
>Unfortunately it is so that my C skills is not that good, that I myself can 
>rewrite valias_select_names_end. 
>
>However I doubt that the old code is the course to the error, but I can not 
>come up with anything better. 
>
>Thanks in advance for any help you are able to provide. 
>
>Best regards,
>Allan Dukat 
>
>Allan Dukat writes: 
>
>> Hi list  
>> 
>> I have a problem with qmailadmin-1.2.16, configured like this:  
>> 
>> ./configure \
>> --enable-vpopmaildir=/home/vpopmail \
>> --enable-htmldir=/usr/local/apache2/htdocs \
>> --enable-cgibindir=/usr/local/apache2/cgi-bin \
>> --enable-imageurl=/images/qmailadmin \
>> --enable-imagedir=/usr/local/apache2/htdocs/images/qmailadmin \
>> --enable-qmaildir=/var/qmail \
>> --enable-ezmlmdir=/usr/local/bin/ezmlm \
>> --enable-cgipath=/cgi-bin/qmailadmin \
>> --enable-autoresponder-path=/usr/local/bin \
>> --enable-vpopuser=vpopmail \
>> --enable-vpopgroup=vchkpw \
>> --disable-ezmlm-mysql \
>> --enable-modify-quota \
>> --enable-help  
>> 
>> When adding the fist Forward I got an empty page as answer, an this in
>> Apache errorlog:  
>> 
>> *** glibc detected *** /usr/local/apache2/cgi-bin/qmailadmin: double free 
>> or corruption (top): 0x01f326e0 ***
>> === Backtrace: =
>> /lib/x86_64-linux-gnu/libc.so.6(+0x7eb96)[0x7f9ed7c8ab96]
>> /usr/local/apache2/cgi-bin/qmailadmin[0x421f04]
>> /usr/local/apache2/cgi-bin/qmailadmin[0x4219ad]
>> /usr/local/apache2/cgi-bin/qmailadmin[0x42202f]
>> /usr/local/apache2/cgi-bin/qmailadmin[0x40715d]
>> /usr/local/apache2/cgi-bin/qmailadmin[0x4070a3]
>> /usr/local/apache2/cgi-bin/qmailadmin[0x4054f5]
>> /usr/local/apache2/cgi-bin/qmailadmin[0x4130c3]
>> /usr/local/apache2/cgi-bin/qmailadmin[0x402db6]
>> /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xed)[0x7f9ed7c2d76d]
>> /usr/local/apache2/cgi-bin/qmailadmin[0x402929]  
>> 
>> During debug I have used
>> export CC="gcc -g -Xlinker -Map=../output.map"
>> to make a map-file, and I have "translated" the abowe to:  
>> 
>> /lib/x86_64-linux-gnu/libc.so.6(+0x7eb96)[0x7f9ed7c8ab96]
>> /usr/local/apache2/cgi-bin/qmailadmin[valias_select_names_end]
>> /usr/local/apache2/cgi-bin/qmailadmin[valias_select_names]
>> /usr/local/apache2/cgi-bin/qmailadmin[valias_select_all]
>> /usr/local/apache2/cgi-bin/qmailadmin[count_forwards]
>> /usr/local/apache2/cgi-bin/qmailadmin[show_forwards]
>> /usr/local/apache2/cgi-bin/qmailadmin[adddotqmailnow]
>> /usr/local/apache2/cgi-bin/qmailadmin[process_comands]
>> /usr/local/apache2/cgi-bin/qmailadmin[main]  
>> 
>> The Forward is added, and I can add and list Forwards from now on. When 
>> all Forward is deleted and I add a new Forward the error is repeated with 
>> the same addresses. 
>> 
>> I Use Ubuntu 12.04.2 LTS, x86_64, fully patched.
>> And openssl-1.0.1e, netqmail-1.06, chkuser-2.0.9-release.patch,
>> qmail-authentication-081, ucspi-tcp-0.88, daemontools-0.76, pcre-8.32,
>> maildrop-2.6.0, vpopmail-5.4.33, ezmlm-idx-7.1.1, dovecot-2.2.1, 
>> apr-1.4.6,
>> apr-util-1.5.2, httpd-2.4.4, courier-authlib-0.65.0, sqwebmail-5.6.1,
>> autorespond-2.0.4, qmailadmin-1.2.16, qmailadmin-help-1.0.8 and
>> vqadmin-2.3.7 all configure-make-install.
>> Spam Filter is elsewhere.  
>> 
>> I have tried with qmailadmin-1.2.15 and qmailadmin-1.2.12 instead, but 
>> with the same result.  
>> 
>> The only problem I see is in the output from the make command of
>> vpopmail-5.4.33:  
>> 
>> 
>> gcc -I. -Icdb  -I.-fPIC  -c -o libvpopmail_a-vpopmail.o `test -f 
>> 'vpopmail.c' || echo './'`vpopmail.c
>> vpopmail.c: In function ‘vadduser’:
>> vpopmail.c:741:9: warning: format ‘%llu’ expects argument of type 
>> ‘long long unsigned int’, but argument 4 has type ‘storage_t’ 
>> [-Wformat]
>> vpopmail.c:741:9: warning: format ‘%llu’ expects argument of type 
>> ‘long long unsigned int’, but argument 5 has type ‘storage_t’ 
>> [-Wformat]
>> vpopmail.c:741:9: warning: format ‘%llu’ expects argument of type 
>> ‘long long unsigned int’, but argument 4 has type ‘storage_t’ 
>> [-Wformat]
>> vpopmail.c:741:9: warning: format ‘%llu’ expects argument of type 
>> ‘long long unsigned int’, but argument 5 has type ‘storage_t’ 
>> [-Wformat]
>> vpopmail.c:743:7: warning: format ‘%llu’ expects argument of type 
>> ‘long long unsigned int’, but argument 4 has type ‘storage_t’ 
>> [-Wformat]
>> vpopmail.c:743:7: warning: format ‘%llu’ expects argument of type 
>> ‘long long unsigned int’, but argument 4 has type ‘storage_t’ 
>> [-Wformat]