diff options
author | Ilia Alshanetsky <iliaa@php.net> | 2005-02-07 22:31:19 +0000 |
---|---|---|
committer | Ilia Alshanetsky <iliaa@php.net> | 2005-02-07 22:31:19 +0000 |
commit | aa6cb1055b0fd0f1e165cea038b1f4d2d99a4816 (patch) | |
tree | 8ab26c3ac522aafb6c1d8752bf60e73e272f7057 /ext/sysvmsg/sysvmsg.c | |
parent | 9c530d79e7f97dfe64af1e7e4200c4f9f1953035 (diff) | |
download | php-git-aa6cb1055b0fd0f1e165cea038b1f4d2d99a4816.tar.gz |
Fixed bug #31527 (crash in msg_send() when non-string is stored without
being serialized).
Diffstat (limited to 'ext/sysvmsg/sysvmsg.c')
-rw-r--r-- | ext/sysvmsg/sysvmsg.c | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/ext/sysvmsg/sysvmsg.c b/ext/sysvmsg/sysvmsg.c index 844b0936fd..ca80c59161 100644 --- a/ext/sysvmsg/sysvmsg.c +++ b/ext/sysvmsg/sysvmsg.c @@ -391,10 +391,33 @@ PHP_FUNCTION(msg_send) message_len = msg_var.len; smart_str_free(&msg_var); } else { - convert_to_string_ex(&message); - messagebuffer = emalloc(sizeof(struct php_msgbuf) + Z_STRLEN_P(message)); - memcpy(messagebuffer->mtext, Z_STRVAL_P(message), Z_STRLEN_P(message) + 1); - message_len = Z_STRLEN_P(message); + char *p; + switch (Z_TYPE_P(message)) { + case IS_STRING: + p = Z_STRVAL_P(message); + message_len = Z_STRLEN_P(message); + break; + + case IS_LONG: + case IS_BOOL: + message_len = spprintf(&p, 0, "%ld", Z_LVAL_P(message)); + break; + + case IS_DOUBLE: + message_len = spprintf(&p, 0, "%f", Z_DVAL_P(message)); + break; + + default: + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Message parameter must be either a string or a number."); + RETURN_FALSE; + } + + messagebuffer = emalloc(sizeof(struct php_msgbuf) + message_len); + memcpy(messagebuffer->mtext, p, message_len + 1); + + if (Z_TYPE_P(message) != IS_STRING) { + efree(p); + } } /* set the message type */ |