summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGustavo Lopes <glopes@nebm.ist.utl.pt>2013-01-31 00:59:05 +0100
committerGustavo Lopes <glopes@nebm.ist.utl.pt>2013-02-02 16:38:08 +0100
commitf10baf14eda4a6fd0e4c8a24d008975184e31207 (patch)
tree0eaf47dbd6f6920417da9348d54d5f047289a904
parentc846fcef685c14a42ae770d56340a41d936deae9 (diff)
downloadphp-git-f10baf14eda4a6fd0e4c8a24d008975184e31207.tar.gz
Payload of HOPLIMIT/TCLASS are 8-bit
-rw-r--r--ext/sockets/conversions.c30
-rw-r--r--ext/sockets/conversions.h4
-rw-r--r--ext/sockets/sendrecvmsg.c10
3 files changed, 36 insertions, 8 deletions
diff --git a/ext/sockets/conversions.c b/ext/sockets/conversions.c
index 9cbc6e5f88..ef1f884210 100644
--- a/ext/sockets/conversions.c
+++ b/ext/sockets/conversions.c
@@ -317,7 +317,7 @@ double_case:
return ret;
}
-void from_zval_write_int(const zval *arr_value, char *field, ser_context *ctx)
+static void from_zval_write_int(const zval *arr_value, char *field, ser_context *ctx)
{
long lval;
int ival;
@@ -355,6 +355,25 @@ static void from_zval_write_uint32(const zval *arr_value, char *field, ser_conte
ival = (uint32_t)lval;
memcpy(field, &ival, sizeof(ival));
}
+void from_zval_write_uint8(const zval *arr_value, char *field, ser_context *ctx)
+{
+ long lval;
+ uint8_t ival;
+
+ lval = from_zval_integer_common(arr_value, ctx);
+ if (ctx->err.has_error) {
+ return;
+ }
+
+ if (lval < 0 || lval > 0xFF) {
+ do_from_zval_err(ctx, "%s", "given PHP integer is out of bounds "
+ "for an unsigned 8-bit integer");
+ return;
+ }
+
+ ival = (uint8_t)lval;
+ memcpy(field, &ival, sizeof(ival));
+}
static void from_zval_write_net_uint16(const zval *arr_value, char *field, ser_context *ctx)
{
long lval;
@@ -441,7 +460,7 @@ static void from_zval_write_uid_t(const zval *arr_value, char *field, ser_contex
memcpy(field, &ival, sizeof(ival));
}
-void to_zval_read_int(const char *data, zval *zv, res_context *ctx)
+static void to_zval_read_int(const char *data, zval *zv, res_context *ctx)
{
int ival;
memcpy(&ival, data, sizeof(ival));
@@ -455,6 +474,13 @@ static void to_zval_read_unsigned(const char *data, zval *zv, res_context *ctx)
ZVAL_LONG(zv, (long)ival);
}
+void to_zval_read_uint8(const char *data, zval *zv, res_context *ctx)
+{
+ uint8_t ival;
+ memcpy(&ival, data, sizeof(ival));
+
+ ZVAL_LONG(zv, (long)ival);
+}
static void to_zval_read_net_uint16(const char *data, zval *zv, res_context *ctx)
{
uint16_t ival;
diff --git a/ext/sockets/conversions.h b/ext/sockets/conversions.h
index 70f31ba676..79ca4ab76e 100644
--- a/ext/sockets/conversions.h
+++ b/ext/sockets/conversions.h
@@ -37,8 +37,8 @@ void err_msg_dispose(struct err_s *err TSRMLS_DC);
void allocations_dispose(zend_llist **allocations);
/* CONVERSION FUNCTIONS */
-void from_zval_write_int(const zval *arr_value, char *field, ser_context *ctx);
-void to_zval_read_int(const char *data, zval *zv, res_context *ctx);
+void from_zval_write_uint8(const zval *arr_value, char *field, ser_context *ctx);
+void to_zval_read_uint8(const char *data, zval *zv, res_context *ctx);
#ifdef IPV6_PKTINFO
void from_zval_write_in6_pktinfo(const zval *container, char *in6_pktinfo_c, ser_context *ctx);
diff --git a/ext/sockets/sendrecvmsg.c b/ext/sockets/sendrecvmsg.c
index b83b3ae482..f325b0378a 100644
--- a/ext/sockets/sendrecvmsg.c
+++ b/ext/sockets/sendrecvmsg.c
@@ -73,12 +73,14 @@ static void init_ancillary_registry(void)
#endif
#ifdef IPV6_HOPLIMIT
- PUT_ENTRY(sizeof(int), 0, 0, from_zval_write_int,
- to_zval_read_int, IPPROTO_IPV6, IPV6_HOPLIMIT);
+ PUT_ENTRY(sizeof(int), 0, 0, from_zval_write_uint8,
+ to_zval_read_uint8, IPPROTO_IPV6, IPV6_HOPLIMIT);
#endif
- PUT_ENTRY(sizeof(int), 0, 0, from_zval_write_int,
- to_zval_read_int, IPPROTO_IPV6, IPV6_TCLASS);
+#ifdef IPV6_TCLASS
+ PUT_ENTRY(sizeof(int), 0, 0, from_zval_write_uint8,
+ to_zval_read_uint8, IPPROTO_IPV6, IPV6_TCLASS);
+#endif
#ifdef SO_PASSCRED
PUT_ENTRY(sizeof(struct ucred), 0, 0, from_zval_write_ucred,