]> granicus.if.org Git - php/commitdiff
Fixed bug #66907 Solaris 10 is missing strcasestr and needs substitute
authorAnatol Belski <ab@php.net>
Tue, 15 Apr 2014 17:26:49 +0000 (10:26 -0700)
committerAnatol Belski <ab@php.net>
Tue, 15 Apr 2014 17:26:49 +0000 (10:26 -0700)
NEWS
ext/fileinfo/config.m4
ext/fileinfo/libmagic/strcasestr.c [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index a5d06dcde01317e5766ddff01654731ca1b6e887..f281f5a36ed1635fab7561d9d71ade324e3b0b65 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -24,6 +24,10 @@ PHP                                                                        NEWS
   . Fixed bug #66721 (__wakeup of DateTime segfaults when invalid object data is
     supplied). (Boro Sitnikovski)
 
+- Fileinfo:
+  . Fixed bug #66907 (Solaris 10 is missing strcasestr and needs substitute).
+    (Anatol)
+
 - FPM:
   . Fixed bug #66482 (unknown entry 'priority' in php-fpm.conf).
 
index 4f340412599521a334555283481f2cd3b6e92ace..a11dbf8dac391bcb15ff34f1e2cd6205a63b1f53 100644 (file)
@@ -13,6 +13,41 @@ if test "$PHP_FILEINFO" != "no"; then
     libmagic/is_tar.c libmagic/magic.c libmagic/print.c \
     libmagic/readcdf.c libmagic/readelf.c libmagic/softmagic.c"
 
+  AC_MSG_CHECKING([for strcasestr])
+  AC_TRY_RUN([
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+
+int main(void)
+{
+        char *s0, *s1, *ret;
+
+        s0 = (char *) malloc(42);
+        s1 = (char *) malloc(8);
+
+        memset(s0, 'X', 42);
+        s0[24] = 'Y';
+        s0[26] = 'Z';
+        s0[41] = '\0';
+        memset(s1, 'x', 8);
+        s1[0] = 'y';
+        s1[2] = 'Z';
+        s1[7] = '\0';
+
+        ret = strcasestr(s0, s1);
+
+        return !(NULL != ret);
+}
+  ],[
+    dnl using the platform implementation
+    AC_MSG_RESULT(yes)
+  ],[
+    AC_MSG_RESULT(no)
+    AC_MSG_NOTICE(using libmagic strcasestr implementation)
+    libmagic_sources="$libmagic_sources libmagic/strcasestr.c"
+  ])
+
   PHP_NEW_EXTENSION(fileinfo, fileinfo.c $libmagic_sources, $ext_shared,,-I@ext_srcdir@/libmagic)
   PHP_ADD_BUILD_DIR($ext_builddir/libmagic)
 
diff --git a/ext/fileinfo/libmagic/strcasestr.c b/ext/fileinfo/libmagic/strcasestr.c
new file mode 100644 (file)
index 0000000..546ed3f
--- /dev/null
@@ -0,0 +1,82 @@
+/*     $NetBSD: strcasestr.c,v 1.3 2005/11/29 03:12:00 christos Exp $  */
+
+/*-
+ * Copyright (c) 1990, 1993
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: strcasestr.c,v 1.3 2005/11/29 03:12:00 christos Exp $");
+__RCSID("$NetBSD: strncasecmp.c,v 1.2 2007/06/04 18:19:27 christos Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include <assert.h>
+#include <ctype.h>
+#include <string.h>
+
+static int
+_strncasecmp(const char *s1, const char *s2, size_t n)
+{
+       if (n != 0) {
+               const unsigned char *us1 = (const unsigned char *)s1,
+                               *us2 = (const unsigned char *)s2;
+
+               do {
+                       if (tolower(*us1) != tolower(*us2++))
+                               return tolower(*us1) - tolower(*--us2);
+                       if (*us1++ == '\0')
+                               break;
+               } while (--n != 0);
+       }
+       return 0;
+}
+
+/*
+ * Find the first occurrence of find in s, ignore case.
+ */
+char *
+strcasestr(const char *s, const char *find)
+{
+       char c, sc;
+       size_t len;
+
+       if ((c = *find++) != 0) {
+               c = tolower((unsigned char)c);
+               len = strlen(find);
+               do {
+                       do {
+                               if ((sc = *s++) == 0)
+                                       return (NULL);
+                       } while ((char)tolower((unsigned char)sc) != c);
+               } while (_strncasecmp(s, find, len) != 0);
+               s--;
+       }
+       return (char *)(intptr_t)(s);
+}