vfs: check userland buffers before reading them.
[haiku.git] / src / tests / servers / input / comm / port.cpp
blobf93aae44f05f83ae47293eb95eb64592be73a12e
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <OS.h>
4 #include <Message.h>
6 int main(int count, char **args) {
8 sem_id portSem = atoi(args[2]);
9 port_id port = atoi(args[1]);
11 for (int i=0; i<10; i++) {
13 acquire_sem(portSem);
15 ssize_t size = port_buffer_size(port);
16 printf("size : %ld\n", size);
18 char buffer[size];
19 int32 code;
20 ssize_t newsize;
21 if ((newsize = read_port(port, &code, buffer, size))==size) {
22 BMessage msg;
23 if (msg.Unflatten(buffer)!=B_OK) {
24 printf("error \n");
25 } else {
26 msg.PrintToStream();
28 } else {
29 printf("error %ld\n", newsize);