112
/*
113
* The client sent a command followed by a (possibly very) large buffer.
114
*/
115
-static int app__sendbytes_command(const char *received,
115
+static int app__sendbytes_command(const char *received, size_t received_len,
116
ipc_server_reply_cb *reply_cb,
117
struct ipc_server_reply_data *reply_data)
118
{
123
int errs = 0;
124
int ret;
125
126
+ /*
127
+ * The test is setup to send:
128
+ * "sendbytes" SP <n * char>
129
+ */
130
+ if (received_len < strlen("sendbytes "))
131
+ BUG("received_len is short in app__sendbytes_command");
132
+
133
if (skip_prefix(received, "sendbytes ", &p))
134
len_ballast = strlen(p);
135
167
* by this application.
168
*/
169
static int test_app_cb(void *application_data,
163
- const char *command,
170
+ const char *command, size_t command_len,
171
ipc_server_reply_cb *reply_cb,
172
struct ipc_server_reply_data *reply_data)
173
{
180
if (application_data != (void*)&my_app_data)
181
BUG("application_cb: application_data pointer wrong");
182
176
- if (!strcmp(command, "quit")) {
183
+ if (command_len == 4 && !strncmp(command, "quit", 4)) {
184
/*
185
* The client sent a "quit" command. This is an async
186
* request for the server to shutdown.
200
return SIMPLE_IPC_QUIT;
201
}
202
196
- if (!strcmp(command, "ping")) {
203
+ if (command_len == 4 && !strncmp(command, "ping", 4)) {
204
const char *answer = "pong";
205
return reply_cb(reply_data, answer, strlen(answer));
206
}
207
201
- if (!strcmp(command, "big"))
208
+ if (command_len == 3 && !strncmp(command, "big", 3))
209
return app__big_command(reply_cb, reply_data);
210
204
- if (!strcmp(command, "chunk"))
211
+ if (command_len == 5 && !strncmp(command, "chunk", 5))
212
return app__chunk_command(reply_cb, reply_data);
213
207
- if (!strcmp(command, "slow"))
214
+ if (command_len == 4 && !strncmp(command, "slow", 4))
215
return app__slow_command(reply_cb, reply_data);
216
210
- if (starts_with(command, "sendbytes "))
211
- return app__sendbytes_command(command, reply_cb, reply_data);
217
+ if (command_len >= 10 && starts_with(command, "sendbytes "))
218
+ return app__sendbytes_command(command, command_len,
219
+ reply_cb, reply_data);
220
221
return app__unhandled_command(command, reply_cb, reply_data);
222
}
496
options.wait_if_busy = 1;
497
options.wait_if_not_found = 0;
498
491
- if (!ipc_client_send_command(cl_args.path, &options, command, &buf)) {
499
+ if (!ipc_client_send_command(cl_args.path, &options,
500
+ command, strlen(command),
501
+ &buf)) {
502
if (buf.len) {
503
printf("%s\n", buf.buf);
504
fflush(stdout);
566
strbuf_addstr(&buf_send, "sendbytes ");
567
strbuf_addchars(&buf_send, byte, bytecount);
568
559
- if (!ipc_client_send_command(path, options, buf_send.buf, &buf_resp)) {
569
+ if (!ipc_client_send_command(path, options,
570
+ buf_send.buf, buf_send.len,
571
+ &buf_resp)) {
572
strbuf_rtrim(&buf_resp);
573
printf("sent:%c%08d %s\n", byte, bytecount, buf_resp.buf);
574
fflush(stdout);