ID: 15638 Updated by: [EMAIL PROTECTED] Reported By: [EMAIL PROTECTED] Status: Closed Bug Type: ICONV related Operating System: Linux PHP Version: 4.0CVS-2002-02-19 New Comment:
The latest changes in ext/iconv/iconv.c (rev. 1.27, 1.28) are wrong. I suggest to revert to version 1.26 and then apply the right fix (below). I sent that patch but failed to verify that it was applied correctly to CVS (I have it applied to php-4.0.6 on my runnung system). --- ext/iconv/iconv.c.1.26 Wed Feb 27 08:40:51 2002 +++ ext/iconv/iconv.c Wed Feb 27 08:42:35 2002 @@ -167,7 +167,7 @@ } *out_len = out_size - out_left; - out[*out_len] = '\0'; + out_buffer[*out_len] = '\0'; icv_close(cd); return SUCCESS; ---- Writing the null byte to out[*out_len] is actually assigining a NULL pointer at some random location and may cause a seg. fault or other weird behavior. On a second thought, this should work just as well: *out_p = '\0'; Using calloc instead of malloc is less efficient as it needs to zero all the bytes in the returned string. Adding 1 to the length (as the hange in 1.28) actually increases the length of the result - which is not what we wanted. Try this small program to see the result: <? $src = 'ISO-8859-1'; $dst = 'ISO-8859-2'; $f = "Hello world."; $t = iconv($src,$dst,$f); printf("strlen('%s') = %d\nstrlen('%s') = %d\n", $f, strlen($f), $t, strlen($t)); ?> Previous Comments: ------------------------------------------------------------------------ [2002-02-20 11:17:51] [EMAIL PROTECTED] Yes, seems to be working now again. Thanks! Now I can start doing something useful with it. :-) Just to let you know, compiling gave me the following warning but it seems to be harmless: iconv.c: In function `php_iconv_string': iconv.c:162: warning: passing arg 2 of `libiconv' from incompatible pointer type ------------------------------------------------------------------------ [2002-02-20 10:53:39] [EMAIL PROTECTED] Now it's fixed (i hope :) Derick ------------------------------------------------------------------------ [2002-02-20 09:46:56] [EMAIL PROTECTED] I'm just recompiling PHP with iconv support to check it out. Assinging to myself. Derick ------------------------------------------------------------------------ [2002-02-20 09:44:04] [EMAIL PROTECTED] If anyone can get use of it, this is the strace result. If I interpret it correctly there is a segfault but it isn't reported in the apache logs. accept(20, {sin_family=AF_INET, sin_port=htons(1658), sin_addr=inet_addr("192.168.60.136")}}, [16]) = 4 rt_sigaction(SIGUSR1, {SIG_IGN}, {0x805e4b0, [], SA_INTERRUPT|0x4000000}, 8) = 0 getsockname(4, {sin_family=AF_INET, sin_port=htons(80), sin_addr=inet_addr("80.130.200.232")}}, [16]) = 0 setsockopt(4, IPPROTO_TCP1, [1], 4) = 0 brk(0x8180000) = 0x8180000 brk(0x8183000) = 0x8183000 alarm(60) = 0 read(4, "GET /headhorde/iconv.php HTTP/1."..., 4096) = 367 rt_sigaction(SIGUSR1, {SIG_IGN}, {SIG_IGN}, 8) = 0 time(NULL) = 1014214048 alarm(60) = 60 alarm(0) = 60 gettimeofday({1014214048, 189959}, NULL) = 0 stat64("/usr/local/httpd/htdocs/headhorde/iconv.php", {st_mode=S_IFREG|0644, st_size=390, ...}) = 0 lstat64("/usr", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat64("/usr/local", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat64("/usr/local/httpd", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat64("/usr/local/httpd/htdocs", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 alarm(60) = 0 umask(077) = 022 umask(022) = 077 brk(0x8186000) = 0x8186000 setitimer(ITIMER_PROF, {it_interval={0, 0}, it_value={30, 0}}, NULL) = 0 rt_sigaction(SIGPROF, {0x4031cc50, [], SA_RESTART|0x4000000}, {SIG_DFL}, 8) = 0 rt_sigprocmask(SIG_UNBLOCK, [PROF], NULL, 8) = 0 brk(0x8187000) = 0x8187000 brk(0x8188000) = 0x8188000 brk(0x8189000) = 0x8189000 brk(0x818a000) = 0x818a000 brk(0x818b000) = 0x818b000 brk(0x818c000) = 0x818c000 brk(0x818d000) = 0x818d000 brk(0x818e000) = 0x818e000 time(NULL) = 1014214048 getpid() = 30325 gettimeofday({1014214048, 215019}, NULL) = 0 getpid() = 30325 getcwd("/root/cvs/cvsphp", 4095) = 17 chdir("/usr/local/httpd/htdocs/headhorde") = 0 open("/usr/local/httpd/htdocs/headhorde/iconv.php", O_RDONLY|O_LARGEFILE) = 6 getcwd("/usr/local/httpd/htdocs/headhorde", 4095) = 34 lstat("/usr", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat("/usr/local", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat("/usr/local/httpd", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat("/usr/local/httpd/htdocs", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat("/usr/local/httpd/htdocs/headhorde", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat("/usr/local/httpd/htdocs/headhorde/iconv.php", {st_mode=S_IFREG|0644, st_size=390, ...}) = 0 brk(0x8193000) = 0x8193000 ioctl(6, TCGETS, 0xbfffe0ac) = -1 ENOTTY (Inappropriate ioctl for device) read(6, "<pre>\r\n<?\r\n error_reporting(E_A"..., 8192) = 390 read(6, "", 7802) = 0 read(6, "", 8192) = 0 ioctl(6, TCGETS, 0xbfffd088) = -1 ENOTTY (Inappropriate ioctl for device) close(6) = 0 alarm(60) = 60 alarm(0) = 60 chdir("/root/cvs/cvsphp") = 0 rt_sigaction(SIGSEGV, {SIG_DFL}, {SIG_DFL}, 8) = 0 setitimer(ITIMER_PROF, {it_interval={0, 0}, it_value={0, 0}}, NULL) = 0 umask(022) = 022 alarm(0) = 0 alarm(60) = 0 alarm(0) = 60 select(5, [4], NULL, NULL, {0, 0}) = 0 (Timeout) write(4, "HTTP/1.1 200 OK\r\nDate: Wed, 20 F"..., 999) = 999 time(NULL) = 1014214048 write(21, "192.168.60.136 - - [20/Feb/2002:"..., 158) = 158 gettimeofday({1014214048, 297068}, NULL) = 0 times({tms_utime=256, tms_stime=67, tms_cutime=0, tms_cstime=0}) = 60732594 rt_sigaction(SIGUSR1, {0x805e4b0, [], SA_INTERRUPT|0x4000000}, {SIG_IGN}, 8) = 0 alarm(15) = 0 ------------------------------------------------------------------------ [2002-02-20 08:52:17] [EMAIL PROTECTED] With. But unfortunately my apache is without. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/15638 -- Edit this bug report at http://bugs.php.net/?id=15638&edit=1