Skip to content

Commit 402c874

Browse files
committed
deal with null bytes in buffer from get/setsockopt
1 parent bb07b44 commit 402c874

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

lib_eio_linux/eio_stubs.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ CAMLprim value caml_eio_sockopt_string_set(value v_fd, value v_level, value v_op
265265
CAMLparam4(v_fd, v_level, v_option, v_val);
266266
const char *str = String_val(v_val);
267267
int ret = setsockopt(Int_val(v_fd), Int_val(v_level), Int_val(v_option),
268-
str, strlen(str) + 1);
268+
str, caml_string_length(v_val));
269269
if (ret == -1) uerror("setsockopt", Nothing);
270270
CAMLreturn(Val_unit);
271271
}
@@ -278,7 +278,6 @@ CAMLprim value caml_eio_sockopt_string_get(value v_fd, value v_level, value v_op
278278
int ret = getsockopt(Int_val(v_fd), Int_val(v_level), Int_val(v_option),
279279
buffer, &len);
280280
if (ret == -1) uerror("getsockopt", Nothing);
281-
buffer[len < sizeof(buffer) ? len : sizeof(buffer) - 1] = '\0';
282-
v_result = caml_copy_string(buffer);
281+
v_result = caml_alloc_initialized_string(len, buffer);
283282
CAMLreturn(v_result);
284283
}

0 commit comments

Comments
 (0)