Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Bug 22600: fix possible segfault in 64 bit systems

Because of a missing include the compiler was implicitly declaring the
PHP functions for throwing exceptions. This could segfault in a 64-bit
system because the pointer returned from zend_exception_get_default was
being truncated to a 32-bit value.

This fixes the problem, enables all compiler warnings, and cleans-up
some other code a bit.
  • Loading branch information...
commit f0b92c680b115dd78c2d6c033d2cdc73b20f46a3 1 parent 9a833fe
@lcastelli authored
Showing with 11 additions and 9 deletions.
  1. +3 −3 chdb.c
  2. +1 −1  config.m4
  3. +7 −5 php_chdb.c
View
6 chdb.c
@@ -127,13 +127,13 @@ static int chdb_read_header(int fd, uint64_t *file_size)
chdb_t *chdb_open(const char* pathname)
{
int fd, _errno = 0;
- uint64_t size;
+ uint64_t size = 0;
chdb_t *chdb = NULL;
if ((fd = open(pathname, O_RDONLY)) < 0)
return NULL; /* errno is already set */
- if (_errno = chdb_read_header(fd, &size))
+ if ((_errno = chdb_read_header(fd, &size)))
goto close_fd;
if ((chdb = mmap(NULL, (size_t)size, PROT_READ, MAP_SHARED, fd, 0))
@@ -322,7 +322,7 @@ int chdb_create(struct chdb_reader *reader, const char *pathname)
cmph_t *mph;
FILE *out;
- if (_errno = chdb_generate_hash(reader, &mph))
+ if ((_errno = chdb_generate_hash(reader, &mph)))
goto return_error;
if ((out = fopen(pathname, "w")) == NULL) {
View
2  config.m4
@@ -38,6 +38,6 @@ if test "$PHP_CHDB" != "no"; then
PHP_SUBST(CHDB_SHARED_LIBADD)
AC_C_BIGENDIAN()
- PHP_NEW_EXTENSION(chdb, chdb.c php_chdb.c, $ext_shared)
+ PHP_NEW_EXTENSION(chdb, chdb.c php_chdb.c, $ext_shared, , "-Wall")
fi
View
12 php_chdb.c
@@ -6,6 +6,7 @@
#include <php_ini.h>
#include <ext/standard/info.h>
+#include <Zend/zend_exceptions.h>
#include <stdio.h>
#include <string.h>
#include "chdb.h"
@@ -39,14 +40,15 @@ static void php_chdb_reader_next(struct chdb_reader *reader,
{
char *my_key;
uint my_key_len;
- long idx;
+ ulong idx;
zval **cur;
struct php_chdb_reader_private *private = reader->private;
if (zend_hash_get_current_key_ex(private->data, &my_key, &my_key_len,
&idx, 0, &private->pos) == HASH_KEY_IS_LONG) {
/* convert the key to string */
- my_key_len = snprintf(private->key_buffer, KEY_BUFFER_LEN, "%ld", idx);
+ my_key_len = snprintf(private->key_buffer, KEY_BUFFER_LEN,
+ "%ld", idx);
my_key = private->key_buffer;
} else {
/* ignore NULL string terminator */
@@ -54,7 +56,8 @@ static void php_chdb_reader_next(struct chdb_reader *reader,
}
/* convert the value to string */
- zend_hash_get_current_data_ex(private->data, (void **)&cur, &private->pos);
+ zend_hash_get_current_data_ex(private->data,
+ (void **)&cur, &private->pos);
zval_dtor(&private->val_copy); /* delete the last copy */
private->val_copy = **cur;
zval_copy_ctor(&private->val_copy);
@@ -168,8 +171,7 @@ static PHP_METHOD(chdb, __construct)
{
char *pathname;
uint pathname_len;
- ulong pathname_hash;
- chdb_t *chdb, **lookup;
+ chdb_t *chdb;
zval *object = getThis();
struct php_chdb *intern = (struct php_chdb *)
zend_object_store_get_object(object TSRMLS_CC);
Please sign in to comment.
Something went wrong with that request. Please try again.