cvs: php4 /ext/bz2 bz2.c

From: Date: Thu, 21 Mar 2002 16:41:24 +0000
Subject: cvs: php4 /ext/bz2 bz2.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-10532@lists.php.net to get a copy of this message
sterling Thu Mar 21 11:41:24 2002 EDT Modified files: /php4/ext/bz2 bz2.c Log: 1) ws fixes 2) un-NUL terminate strings... Binary Data should not be NUL terminated, PHP *is* binary safe... Index: php4/ext/bz2/bz2.c diff -u php4/ext/bz2/bz2.c:1.39 php4/ext/bz2/bz2.c:1.40 --- php4/ext/bz2/bz2.c:1.39 Wed Mar 20 21:34:06 2002 +++ php4/ext/bz2/bz2.c Thu Mar 21 11:41:24 2002 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: bz2.c,v 1.39 2002/03/21 02:34:06 wez Exp $ */ +/* $Id: bz2.c,v 1.40 2002/03/21 16:41:24 sterling Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -82,11 +82,12 @@ static size_t php_bz2iop_read(php_stream *stream, char *buf, size_t count TSRMLS_DC) { - struct php_bz2_stream_data_t *self = (struct php_bz2_stream_data_t *)stream->abstract; + struct php_bz2_stream_data_t *self = (struct php_bz2_stream_data_t *) stream->abstract; if (buf == NULL && count == 0) { /* we have no way of knowing, so let them try to read some more; - * then they will get an error and can stop */ + * then they will get an error and can stop + */ return 0; } @@ -95,7 +96,8 @@ static size_t php_bz2iop_write(php_stream *stream, const char *buf, size_t count TSRMLS_DC) { - struct php_bz2_stream_data_t *self = (struct php_bz2_stream_data_t *)stream->abstract; + struct php_bz2_stream_data_t *self = (struct php_bz2_stream_data_t *) stream->abstract; + return BZ2_bzwrite(self->bz_file, (char*)buf, count); } @@ -106,8 +108,13 @@ if (close_handle) BZ2_bzclose(self->bz_file); + if (self->stream) - php_stream_free(self->stream, PHP_STREAM_FREE_CLOSE | (close_handle == 0 ? PHP_STREAM_FREE_PRESERVE_HANDLE : 0)); + php_stream_free(self->stream, + PHP_STREAM_FREE_CLOSE | + (close_handle == 0 ? PHP_STREAM_FREE_PRESERVE_HANDLE : 0) + ); + efree(self); return ret; @@ -128,7 +135,10 @@ }; /* {{{ Bzip2 stream openers */ -PHPAPI php_stream *_php_stream_bz2open_from_BZFILE(BZFILE *bz, char *mode, php_stream *innerstream STREAMS_DC TSRMLS_DC) +PHPAPI php_stream *_php_stream_bz2open_from_BZFILE(BZFILE *bz, + char *mode, + php_stream *innerstream + STREAMS_DC TSRMLS_DC) { struct php_bz2_stream_data_t *self; @@ -140,7 +150,12 @@ return php_stream_alloc_rel(&php_stream_bz2io_ops, self, 0, mode); } -PHPAPI php_stream *_php_stream_bz2open(char *path, char *mode, int options, char **opened_path, void *wrappercontext STREAMS_DC TSRMLS_DC) +PHPAPI php_stream *_php_stream_bz2open(char *path, + char *mode, + int options, + char **opened_path, + void *wrappercontext + STREAMS_DC TSRMLS_DC) { php_stream *retstream = NULL, *stream = NULL; char *path_copy; @@ -171,17 +186,19 @@ if (stream) { int fd; - if (SUCCESS == php_stream_cast(stream, PHP_STREAM_AS_FD, (void**)&fd, REPORT_ERRORS)) + if (SUCCESS == php_stream_cast(stream, PHP_STREAM_AS_FD, (void**) &fd, REPORT_ERRORS)) bz_file = BZ2_bzdopen(fd, mode); } } - if (bz_file) { + if (bz_file) { retstream = _php_stream_bz2open_from_BZFILE(bz_file, mode, stream STREAMS_REL_CC TSRMLS_CC); if (retstream) return retstream; + BZ2_bzclose(bz_file); } + if (stream) php_stream_close(stream); @@ -190,7 +207,7 @@ /* }}} */ -php_stream_wrapper php_stream_bzip2_wrapper = { +php_stream_wrapper php_stream_bzip2_wrapper = { _php_stream_bz2open, NULL, NULL @@ -200,9 +217,8 @@ PHP_MINIT_FUNCTION(bz2) { - if(PG(allow_url_fopen)) { + if(PG(allow_url_fopen)) php_register_url_stream_wrapper("bz2", &php_stream_bzip2_wrapper TSRMLS_CC); - } return SUCCESS; } @@ -211,6 +227,7 @@ { if (PG(allow_url_fopen)) php_unregister_url_stream_wrapper("bz2" TSRMLS_CC); + return SUCCESS; } @@ -241,13 +258,23 @@ /* If it's not a resource its a string containing the filename to open */ if (Z_TYPE_PP(file) != IS_RESOURCE) { convert_to_string_ex(file); - stream = php_stream_bz2open(path, Z_STRVAL_PP(mode), ENFORCE_SAFE_MODE|REPORT_ERRORS, NULL, NULL); + stream = php_stream_bz2open(path, + Z_STRVAL_PP(mode), + ENFORCE_SAFE_MODE|REPORT_ERRORS, + NULL, + NULL); } else { /* If it is a resource, than its a stream resource */ int type; int fd; - stream = (php_stream *)zend_fetch_resource(file TSRMLS_CC, -1, "File-Handle", &type, 1, php_file_le_stream()); + stream = (php_stream *) zend_fetch_resource(file + TSRMLS_CC, + -1, + "File-Handle", + &type, + 1, + php_file_le_stream()); ZEND_VERIFY_RESOURCE(stream); if (!php_stream_cast(stream, PHP_STREAM_AS_FD, (void*)&fd, REPORT_ERRORS)) RETURN_FALSE; @@ -347,7 +374,6 @@ /* Copy the buffer, we have perhaps allocate alot more than we need, so we erealloc() the buffer to the proper size */ dest = erealloc(dest, size + 1); - dest[size] = '\0'; RETURN_STRINGL(dest, size, 0); } } @@ -413,7 +439,6 @@ /* we might have allocated a little to much, so erealloc the buffer down to size, before returning it */ dest = erealloc(dest, size + 1); - dest[size] = '\0'; RETURN_STRINGL(dest, size, 0); } } @@ -439,7 +464,7 @@ RETURN_FALSE; } - self = (struct php_bz2_stream_data_t *)stream->abstract; + self = (struct php_bz2_stream_data_t *) stream->abstract; /* Fetch the error information */ errstr = BZ2_bzerror(self->bz_file, &errnum);

« previous php.cvs (#10532) next »