Skip to content

Commit 11b119d

Browse files
committed
fix datatype mismatches
1 parent 82c36cf commit 11b119d

File tree

5 files changed

+33
-41
lines changed

5 files changed

+33
-41
lines changed

ext/standard/url_scanner_ex.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ static PHP_INI_MH(OnUpdateTags)
7979
val = strchr(key, '=');
8080
if (val) {
8181
char *q;
82-
int keylen;
82+
size_t keylen;
8383

8484
*val++ = '\0';
8585
for (q = key; *q; q++)
@@ -351,7 +351,7 @@ static inline void xx_mainloop(url_adapt_state_ex_t *ctx, const char *newdata, s
351351
char *end, *q;
352352
char *xp;
353353
char *start;
354-
int rest;
354+
size_t rest;
355355

356356
smart_str_appendl(&ctx->buf, newdata, newlen);
357357

@@ -906,10 +906,13 @@ static inline void xx_mainloop(url_adapt_state_ex_t *ctx, const char *newdata, s
906906

907907

908908
stop:
909-
rest = YYLIMIT - start;
910-
scdebug(("stopped in state %d at pos %d (%d:%c) %d\n", STATE, YYCURSOR - ctx->buf.c, *YYCURSOR, *YYCURSOR, rest));
911-
/* XXX: Crash avoidance. Need to work with reporter to figure out what goes wrong */
912-
if (rest < 0) rest = 0;
909+
if (YYLIMIT < start) {
910+
/* XXX: Crash avoidance. Need to work with reporter to figure out what goes wrong */
911+
rest = 0;
912+
} else {
913+
rest = YYLIMIT - start;
914+
scdebug(("stopped in state %d at pos %d (%d:%c) %d\n", STATE, YYCURSOR - ctx->buf.c, *YYCURSOR, *YYCURSOR, rest));
915+
}
913916

914917
if (rest) memmove(ctx->buf.s->val, start, rest);
915918
ctx->buf.s->len = rest;
@@ -993,7 +996,7 @@ static int php_url_scanner_ex_deactivate(TSRMLS_D)
993996
return SUCCESS;
994997
}
995998

996-
static void php_url_scanner_output_handler(char *output, uint output_len, char **handled_output, uint *handled_output_len, int mode TSRMLS_DC)
999+
static void php_url_scanner_output_handler(char *output, size_t output_len, char **handled_output, size_t *handled_output_len, int mode TSRMLS_DC)
9971000
{
9981001
size_t len;
9991002

@@ -1023,7 +1026,7 @@ static void php_url_scanner_output_handler(char *output, uint output_len, char *
10231026
}
10241027
}
10251028

1026-
PHPAPI int php_url_scanner_add_var(char *name, int name_len, char *value, int value_len, int urlencode TSRMLS_DC)
1029+
PHPAPI int php_url_scanner_add_var(char *name, size_t name_len, char *value, size_t value_len, int urlencode TSRMLS_DC)
10271030
{
10281031
smart_str val = {0};
10291032
zend_string *encoded;

ext/standard/url_scanner_ex.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ PHP_RINIT_FUNCTION(url_scanner_ex);
2828
PHP_RSHUTDOWN_FUNCTION(url_scanner_ex);
2929

3030
PHPAPI char *php_url_scanner_adapt_single_url(const char *url, size_t urllen, const char *name, const char *value, size_t *newlen TSRMLS_DC);
31-
PHPAPI int php_url_scanner_add_var(char *name, int name_len, char *value, int value_len, int urlencode TSRMLS_DC);
31+
PHPAPI int php_url_scanner_add_var(char *name, size_t name_len, char *value, size_t value_len, int urlencode TSRMLS_DC);
3232
PHPAPI int php_url_scanner_reset_vars(TSRMLS_D);
3333

3434
#include "zend_smart_str_public.h"

ext/standard/url_scanner_ex.re

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ static PHP_INI_MH(OnUpdateTags)
7777
val = strchr(key, '=');
7878
if (val) {
7979
char *q;
80-
int keylen;
80+
size_t keylen;
8181

8282
*val++ = '\0';
8383
for (q = key; *q; q++)
@@ -287,7 +287,7 @@ static inline void xx_mainloop(url_adapt_state_ex_t *ctx, const char *newdata, s
287287
char *end, *q;
288288
char *xp;
289289
char *start;
290-
int rest;
290+
size_t rest;
291291

292292
smart_str_appendl(&ctx->buf, newdata, newlen);
293293

@@ -358,10 +358,13 @@ state_val:
358358
*/
359359

360360
stop:
361-
rest = YYLIMIT - start;
362-
scdebug(("stopped in state %d at pos %d (%d:%c) %d\n", STATE, YYCURSOR - ctx->buf.c, *YYCURSOR, *YYCURSOR, rest));
363-
/* XXX: Crash avoidance. Need to work with reporter to figure out what goes wrong */
364-
if (rest < 0) rest = 0;
361+
if (YYLIMIT < start) {
362+
/* XXX: Crash avoidance. Need to work with reporter to figure out what goes wrong */
363+
rest = 0;
364+
} else {
365+
rest = YYLIMIT - start;
366+
scdebug(("stopped in state %d at pos %d (%d:%c) %d\n", STATE, YYCURSOR - ctx->buf.c, *YYCURSOR, *YYCURSOR, rest));
367+
}
365368

366369
if (rest) memmove(ctx->buf.s->val, start, rest);
367370
ctx->buf.s->len = rest;
@@ -445,7 +448,7 @@ static int php_url_scanner_ex_deactivate(TSRMLS_D)
445448
return SUCCESS;
446449
}
447450

448-
static void php_url_scanner_output_handler(char *output, uint output_len, char **handled_output, uint *handled_output_len, int mode TSRMLS_DC)
451+
static void php_url_scanner_output_handler(char *output, size_t output_len, char **handled_output, size_t *handled_output_len, int mode TSRMLS_DC)
449452
{
450453
size_t len;
451454

@@ -475,7 +478,7 @@ static void php_url_scanner_output_handler(char *output, uint output_len, char *
475478
}
476479
}
477480

478-
PHPAPI int php_url_scanner_add_var(char *name, int name_len, char *value, int value_len, int urlencode TSRMLS_DC)
481+
PHPAPI int php_url_scanner_add_var(char *name, size_t name_len, char *value, size_t value_len, int urlencode TSRMLS_DC)
479482
{
480483
smart_str val = {0};
481484
zend_string *encoded;

main/output.c

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ static inline void php_output_init_globals(zend_output_globals *G)
8686
/* }}} */
8787

8888
/* {{{ stderr/stdout writer if not PHP_OUTPUT_ACTIVATED */
89-
static int php_output_stdout(const char *str, size_t str_len)
89+
static size_t php_output_stdout(const char *str, size_t str_len)
9090
{
9191
fwrite(str, 1, str_len, stdout);
9292
return str_len;
9393
}
94-
static int php_output_stderr(const char *str, size_t str_len)
94+
static size_t php_output_stderr(const char *str, size_t str_len)
9595
{
9696
fwrite(str, 1, str_len, stderr);
9797
/* See http://support.microsoft.com/kb/190351 */
@@ -100,7 +100,7 @@ static int php_output_stderr(const char *str, size_t str_len)
100100
#endif
101101
return str_len;
102102
}
103-
static int (*php_output_direct)(const char *str, size_t str_len) = php_output_stderr;
103+
static size_t (*php_output_direct)(const char *str, size_t str_len) = php_output_stderr;
104104
/* }}} */
105105

106106
/* {{{ void php_output_header(TSRMLS_D) */
@@ -238,15 +238,8 @@ PHPAPI int php_output_get_status(TSRMLS_D)
238238

239239
/* {{{ int php_output_write_unbuffered(const char *str, size_t len TSRMLS_DC)
240240
* Unbuffered write */
241-
PHPAPI int php_output_write_unbuffered(const char *str, size_t len TSRMLS_DC)
241+
PHPAPI size_t php_output_write_unbuffered(const char *str, size_t len TSRMLS_DC)
242242
{
243-
#if PHP_DEBUG
244-
if (len > UINT_MAX) {
245-
php_error(E_WARNING, "Attempt to output more than UINT_MAX bytes at once; "
246-
"output will be truncated %lu => %lu",
247-
(unsigned long) len, (unsigned long) (len % UINT_MAX));
248-
}
249-
#endif
250243
if (OG(flags) & PHP_OUTPUT_DISABLED) {
251244
return 0;
252245
}
@@ -259,21 +252,14 @@ PHPAPI int php_output_write_unbuffered(const char *str, size_t len TSRMLS_DC)
259252

260253
/* {{{ int php_output_write(const char *str, size_t len TSRMLS_DC)
261254
* Buffered write */
262-
PHPAPI int php_output_write(const char *str, size_t len TSRMLS_DC)
255+
PHPAPI size_t php_output_write(const char *str, size_t len TSRMLS_DC)
263256
{
264-
#if PHP_DEBUG
265-
if (len > UINT_MAX) {
266-
php_error(E_WARNING, "Attempt to output more than UINT_MAX bytes at once; "
267-
"output will be truncated %lu => %lu",
268-
(unsigned long) len, (unsigned long) (len % UINT_MAX));
269-
}
270-
#endif
271257
if (OG(flags) & PHP_OUTPUT_DISABLED) {
272258
return 0;
273259
}
274260
if (OG(flags) & PHP_OUTPUT_ACTIVATED) {
275261
php_output_op(PHP_OUTPUT_HANDLER_WRITE, str, len TSRMLS_CC);
276-
return (int) len;
262+
return len;
277263
}
278264
return php_output_direct(str, len);
279265
}
@@ -1272,7 +1258,7 @@ static int php_output_handler_compat_func(void **handler_context, php_output_con
12721258

12731259
if (func) {
12741260
char *out_str = NULL;
1275-
uint out_len = 0;
1261+
size_t out_len = 0;
12761262

12771263
func(output_context->in.data, output_context->in.used, &out_str, &out_len, output_context->op TSRMLS_CC);
12781264

main/php_output.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ typedef struct _php_output_context {
110110
#define PHP_OUTPUT_TSRMLS(ctx) TSRMLS_FETCH_FROM_CTX((ctx)->tsrm_ls)
111111

112112
/* old-style, stateless callback */
113-
typedef void (*php_output_handler_func_t)(char *output, uint output_len, char **handled_output, uint *handled_output_len, int mode TSRMLS_DC);
113+
typedef void (*php_output_handler_func_t)(char *output, size_t output_len, char **handled_output, size_t *handled_output_len, int mode TSRMLS_DC);
114114
/* new-style, opaque context callback */
115115
typedef int (*php_output_handler_context_func_t)(void **handler_context, php_output_context *output_context);
116116
/* output handler context dtor */
@@ -206,8 +206,8 @@ PHPAPI void php_output_set_implicit_flush(int flush TSRMLS_DC);
206206
PHPAPI const char *php_output_get_start_filename(TSRMLS_D);
207207
PHPAPI int php_output_get_start_lineno(TSRMLS_D);
208208

209-
PHPAPI int php_output_write_unbuffered(const char *str, size_t len TSRMLS_DC);
210-
PHPAPI int php_output_write(const char *str, size_t len TSRMLS_DC);
209+
PHPAPI size_t php_output_write_unbuffered(const char *str, size_t len TSRMLS_DC);
210+
PHPAPI size_t php_output_write(const char *str, size_t len TSRMLS_DC);
211211

212212
PHPAPI int php_output_flush(TSRMLS_D);
213213
PHPAPI void php_output_flush_all(TSRMLS_D);

0 commit comments

Comments
 (0)