summaryrefslogtreecommitdiffstats
path: root/ssdeep-php7.patch
blob: 05dbd4ebfa31c478766fef5b75d2f954ac0ab682 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
From c62cadc78de1ee69ca3643441477b779d0a817e4 Mon Sep 17 00:00:00 2001
From: Remi Collet <remi@php.net>
Date: Mon, 6 Apr 2015 10:30:12 +0200
Subject: [PATCH] PHP 7 compatibility

---
 php_ssdeep.h |  9 +++++++++
 ssdeep.c     | 22 +++++++++++++---------
 2 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/php_ssdeep.h b/php_ssdeep.h
index 5deaa40..9a88de0 100644
--- a/php_ssdeep.h
+++ b/php_ssdeep.h
@@ -47,4 +47,13 @@
 
     extern zend_module_entry php_ssdeep_module_entry;
 #   define phpext_php_ssdeep_ptr &php_ssdeep_module_entry
+
+#if PHP_MAJOR_VERSION < 7
+typedef int strsize_t;
+#define _RETURN_STRING(s)  RETURN_STRING(s, 0);
+#else
+typedef size_t strsize_t;
+#define _RETURN_STRING(s)  { RETVAL_STRING(s); efree(s); return; }
+#endif
+
 #endif
diff --git a/ssdeep.c b/ssdeep.c
index 3cae212..81f4e07 100644
--- a/ssdeep.c
+++ b/ssdeep.c
@@ -67,8 +67,12 @@ ZEND_END_ARG_INFO()
 const zend_function_entry ssdeep_functions[] = {
     PHP_FE(ssdeep_fuzzy_hash, arginfo_ssdeep_fuzzy_hash)
     PHP_FE(ssdeep_fuzzy_hash_filename, arginfo_ssdeep_fuzzy_hash_filename)
-    PHP_FE(ssdeep_fuzzy_compare, arginfo_ssdeep_fuzzy_compare) {
-        NULL, NULL, NULL} /* Must be the last line in ssdeep_functions[] */
+    PHP_FE(ssdeep_fuzzy_compare, arginfo_ssdeep_fuzzy_compare)
+#ifdef PHP_FE_END
+    PHP_FE_END
+#else
+    { NULL, NULL, NULL } /* Must be the last line in ssdeep_functions[] */
+#endif
 };
 /* }}} */
 
@@ -101,16 +105,16 @@ PHP_MINFO_FUNCTION(ssdeep) {
 PHP_FUNCTION(ssdeep_fuzzy_hash) {
     char *hash = (char *) emalloc(FUZZY_MAX_RESULT);
     char *to_hash;
-    int to_hash_len;
+    strsize_t to_hash_len;
 
     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &to_hash, &to_hash_len) == FAILURE) {
         RETURN_NULL();
     }
 
-    if (0 != fuzzy_hash_buf((unsigned char *) to_hash, to_hash_len, hash)) {
+    if (0 != fuzzy_hash_buf((unsigned char *) to_hash, (uint32_t)to_hash_len, hash)) {
         RETURN_FALSE;
     } else {
-        RETURN_STRING(hash, 0);
+        _RETURN_STRING(hash);
     }
 }
 /* }}} */
@@ -120,7 +124,7 @@ PHP_FUNCTION(ssdeep_fuzzy_hash) {
 PHP_FUNCTION(ssdeep_fuzzy_hash_filename) {
     char *hash = (char *) emalloc(FUZZY_MAX_RESULT);
     char *file_name;
-    int file_name_len;
+    strsize_t file_name_len;
 
     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file_name, &file_name_len) == FAILURE) {
         RETURN_NULL();
@@ -129,7 +133,7 @@ PHP_FUNCTION(ssdeep_fuzzy_hash_filename) {
     if (0 != fuzzy_hash_filename(file_name, hash)) {
         RETURN_FALSE;
     } else {
-        RETURN_STRING(hash, 0);
+        _RETURN_STRING(hash);
     }
 }
 /* }}} */
@@ -138,9 +142,9 @@ PHP_FUNCTION(ssdeep_fuzzy_hash_filename) {
  */
 PHP_FUNCTION(ssdeep_fuzzy_compare) {
     char *signature1 = NULL;
-    int signature1_len;
+    strsize_t signature1_len;
     char *signature2 = NULL;
-    int signature2_len;
+    strsize_t signature2_len;
     int match;
     
     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &signature1, &signature1_len, &signature2, &signature2_len) == FAILURE) {
-- 
2.1.0