Fix bug #16936 (patch by pop3 at flachtaucher dot de)

v1.1
Pierrick Charron 2009-11-16 14:52:05 +00:00
parent 265f925b84
commit 9ec595819e
2 changed files with 46 additions and 4 deletions

12
stomp.c
View File

@ -277,6 +277,7 @@ static int stomp_read_buffer(stomp_t *stomp, char **data)
{
int rc = 0;
size_t i = 0;
size_t bufsize = STOMP_BUFSIZE + 1;
char *buffer = (char *) emalloc(STOMP_BUFSIZE + 1);
while (1) {
@ -300,8 +301,9 @@ static int stomp_read_buffer(stomp_t *stomp, char **data)
break;
}
if (i >= sizeof(buffer)) {
buffer = (char *) erealloc(buffer, sizeof(buffer) + STOMP_BUFSIZE);
if (i >= bufsize) {
buffer = (char *) erealloc(buffer, bufsize + STOMP_BUFSIZE);
bufsize += STOMP_BUFSIZE;
}
}
@ -329,6 +331,7 @@ static int stomp_read_line(stomp_t *stomp, char **data)
{
int rc = 0;
size_t i = 0;
size_t bufsize = STOMP_BUFSIZE + 1;
char *buffer = (char *) emalloc(STOMP_BUFSIZE + 1);
while (1) {
@ -351,8 +354,9 @@ static int stomp_read_line(stomp_t *stomp, char **data)
return 0;
}
if (i >= sizeof(buffer)) {
buffer = (char *) erealloc(buffer, sizeof(buffer) + STOMP_BUFSIZE);
if (i >= bufsize) {
buffer = (char *) erealloc(buffer, bufsize + STOMP_BUFSIZE);
bufsize += STOMP_BUFSIZE;
}
}

38
tests/bug_16936.phpt Normal file
View File

@ -0,0 +1,38 @@
--TEST--
Bug #16936 - Module segfaults on readFrame if Frame > STOMP_BUFSIZE
--SKIPIF--
<?php if (!extension_loaded("stomp")) print "skip"; ?>
--FILE--
<?php
$queue = '/queue/foo';
$msg = str_repeat('bar', 3000);
/* connection */
try {
$stomp = new Stomp();
} catch(StompException $e) {
die('Connection failed: ' . $e->getMessage());
}
/* send a message to the queue 'foo' */
$stomp->send($queue, $msg);
/* subscribe to messages from the queue 'foo' */
$stomp->subscribe($queue);
/* read a frame */
$frame = $stomp->readFrame();
if ($frame->body === $msg) {
var_dump($frame->body);
/* acknowledge that the frame was received */
$stomp->ack($frame);
}
/* close connection */
unset($stomp);
?>
--EXPECTF--
string(%d) "%s"