php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #8195 strncasecmp returns incorrect value
Submitted: 2000-12-11 16:08 UTC Modified: 2000-12-12 04:48 UTC
From: kway at wgate dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0 Latest CVS (11/12/2000) OS: FreeBSD 4.2
Private report: No CVE-ID: None
 [2000-12-11 16:08 UTC] kway at wgate dot com
strncasecmp returns len1 - len2, regardless of how many
characters we wanted to compare, thus
strncasecmp('foo', 'foosomethingelse', 3) would return -13
instead of 0, as would be correct.

The following patch fixes this problem properly:

Index: zend_operators.c
===================================================================
RCS file: /repository/Zend/zend_operators.c,v
retrieving revision 1.88
diff -u -5 -r1.88 zend_operators.c
--- zend_operators.c    2000/11/21 22:41:49     1.88
+++ zend_operators.c    2000/12/11 21:06:29
@@ -1561,11 +1561,11 @@
                if (c1 != c2) {
                        return c1 - c2;
                }
        }

-       return len1 - len2;
+       return MIN(length, len1) - MIN(length, len2);
 }


 ZEND_API int zend_binary_zval_strcmp(zval *s1, zval *s2)
 {

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-12-12 04:48 UTC] stas@php.net
Fixed in CVS, thanks.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 03 01:01:33 2024 UTC