@@ -69,67 +69,65 @@ static unsigned char *compute_buffer(unsigned char next_byte, unsigned char *buf
69
69
struct writer_cb_ctx {
70
70
bool verbose;
71
71
unsigned char *template_buf;
72
- ssize_t read_len;
72
+ size_t read_len;
73
73
unsigned char next_byte_read;
74
74
};
75
75
76
76
/* *
77
77
* Consume and verify up to read_len from a BUFQ via callback for Curl_bufq_pass.
78
78
*/
79
- ssize_t bufq_writer_cb (void *writer_ctx,
79
+ CURLcode bufq_writer_cb (void *writer_ctx,
80
80
const unsigned char *buf, size_t len,
81
- CURLcode *err )
81
+ size_t *pnwritten )
82
82
{
83
83
struct writer_cb_ctx *ctx = (struct writer_cb_ctx *)writer_ctx;
84
84
85
- if (ctx->read_len <= 0 ) {
86
- *err = CURLE_AGAIN;
87
- return -1 ;
88
- }
85
+ *pnwritten = 0 ;
86
+ if (ctx->read_len <= 0 )
87
+ return CURLE_AGAIN;
89
88
90
89
FV_PRINTF (ctx->verbose , " Writer CB: %zu space available, %zu pending\n " , len, ctx->read_len );
91
90
92
- size_t sz = len > ctx->read_len ? ctx->read_len : len;
91
+ *pnwritten = len > ctx->read_len ? ctx->read_len : len;
93
92
94
93
unsigned char *compare = compute_buffer (ctx->next_byte_read , ctx->template_buf );
95
- assert (memcmp (buf, compare, sz ) == 0 );
96
- ctx->next_byte_read += sz ;
97
- ctx->read_len -= sz ;
94
+ assert (memcmp (buf, compare, *pnwritten ) == 0 );
95
+ ctx->next_byte_read += *pnwritten ;
96
+ ctx->read_len -= *pnwritten ;
98
97
99
- return sz ;
98
+ return CURLE_OK ;
100
99
}
101
100
102
101
struct reader_cb_ctx {
103
102
bool verbose;
104
103
unsigned char *template_buf;
105
- ssize_t write_len;
104
+ size_t write_len;
106
105
unsigned char next_byte_write;
107
106
};
108
107
109
108
/* *
110
109
* Write up to write_len to a BUFQ via callback for Curl_bufq_slurp/sipn.
111
110
*/
112
- static ssize_t bufq_reader_cb (void *reader_ctx,
111
+ static CURLcode bufq_reader_cb (void *reader_ctx,
113
112
unsigned char *buf, size_t len,
114
- CURLcode *err )
113
+ size_t *pnread )
115
114
{
116
115
struct reader_cb_ctx *ctx = (struct reader_cb_ctx *)reader_ctx;
117
116
118
- if (ctx->write_len <= 0 ) {
119
- *err = CURLE_AGAIN;
120
- return -1 ;
121
- }
117
+ *pnread = 0 ;
118
+ if (ctx->write_len <= 0 )
119
+ return CURLE_AGAIN;
122
120
123
121
FV_PRINTF (ctx->verbose , " Reader CB: %zu space available, %zu pending\n " , len, ctx->write_len );
124
122
125
- size_t sz = len > ctx->write_len ? ctx->write_len : len;
123
+ *pnread = len > ctx->write_len ? ctx->write_len : len;
126
124
127
125
unsigned char *compare = compute_buffer (ctx->next_byte_write , ctx->template_buf );
128
- memcpy (buf, compare, sz );
129
- ctx->next_byte_write += sz ;
130
- ctx->write_len -= sz ;
126
+ memcpy (buf, compare, *pnread );
127
+ ctx->next_byte_write += *pnread ;
128
+ ctx->write_len -= *pnread ;
131
129
132
- return sz ;
130
+ return CURLE_OK ;
133
131
}
134
132
135
133
/* *
@@ -161,7 +159,7 @@ int fuzz_handle_bufq(FuzzedDataProvider *fuzz)
161
159
Curl_bufq_init (&q, chunk_size, max_chunks);
162
160
}
163
161
164
- ssize_t buffer_bytes = 0 ;
162
+ size_t buffer_bytes = 0 ;
165
163
unsigned char next_byte_read = 0 ;
166
164
unsigned char next_byte_write = 0 ;
167
165
while (fuzz->remaining_bytes () > 0 ) {
@@ -213,9 +211,10 @@ int fuzz_handle_bufq(FuzzedDataProvider *fuzz)
213
211
size_t op_size = fuzz->ConsumeIntegralInRange (0 , FUZZ_MAX_RW_SIZE);
214
212
FV_PRINTF (verbose, " OP: read, size %zu\n " , op_size);
215
213
unsigned char *buf = (unsigned char *)malloc (op_size * sizeof (*buf));
216
- ssize_t read = Curl_bufq_read (&q, buf, op_size, &err);
217
- if (read != -1 ) {
218
- FV_PRINTF (verbose, " OP: read, success, read %zd, expect begins with %x\n " , read, next_byte_read);
214
+ size_t read;
215
+ CURLcode result = Curl_bufq_read (&q, buf, op_size, &read);
216
+ if (!result) {
217
+ FV_PRINTF (verbose, " OP: read, success, read %zu, expect begins with %x\n " , read, next_byte_read);
219
218
buffer_bytes -= read;
220
219
assert (buffer_bytes >= 0 );
221
220
unsigned char *compare = compute_buffer (next_byte_read, template_buf);
@@ -229,12 +228,13 @@ int fuzz_handle_bufq(FuzzedDataProvider *fuzz)
229
228
}
230
229
231
230
case OP_TYPE_SLURP: {
232
- ssize_t op_size = fuzz->ConsumeIntegralInRange (0 , FUZZ_MAX_RW_SIZE);
231
+ size_t op_size = fuzz->ConsumeIntegralInRange (0 , FUZZ_MAX_RW_SIZE);
233
232
FV_PRINTF (verbose, " OP: slurp, size %zd\n " , op_size);
234
233
struct reader_cb_ctx ctx = { .verbose = verbose, .template_buf = template_buf, .write_len = op_size, .next_byte_write = next_byte_write };
235
- ssize_t write = Curl_bufq_slurp (&q, bufq_reader_cb, &ctx, &err);
236
- if (write != -1 ) {
237
- FV_PRINTF (verbose, " OP: slurp, success, wrote %zd, expect begins with %x\n " , write, ctx.next_byte_write );
234
+ size_t write;
235
+ CURLcode result = Curl_bufq_slurp (&q, bufq_reader_cb, &ctx, &write);
236
+ if (!result) {
237
+ FV_PRINTF (verbose, " OP: slurp, success, wrote %zu, expect begins with %x\n " , write, ctx.next_byte_write );
238
238
buffer_bytes += write;
239
239
} else {
240
240
FV_PRINTF (verbose, " OP: slurp, error\n " );
@@ -247,12 +247,13 @@ int fuzz_handle_bufq(FuzzedDataProvider *fuzz)
247
247
}
248
248
249
249
case OP_TYPE_SIPN: {
250
- ssize_t op_size = fuzz->ConsumeIntegralInRange (0 , FUZZ_MAX_RW_SIZE);
250
+ size_t op_size = fuzz->ConsumeIntegralInRange (0 , FUZZ_MAX_RW_SIZE);
251
251
FV_PRINTF (verbose, " OP: sipn, size %zd\n " , op_size);
252
252
struct reader_cb_ctx ctx = { .verbose = verbose, .template_buf = template_buf, .write_len = op_size, .next_byte_write = next_byte_write };
253
- ssize_t write = Curl_bufq_sipn (&q, op_size, bufq_reader_cb, &ctx, &err);
254
- if (write != -1 ) {
255
- FV_PRINTF (verbose, " OP: sipn, success, wrote %zd, expect begins with %x\n " , write, ctx.next_byte_write );
253
+ size_t write;
254
+ CURLcode result = Curl_bufq_sipn (&q, op_size, bufq_reader_cb, &ctx, &write);
255
+ if (!result) {
256
+ FV_PRINTF (verbose, " OP: sipn, success, wrote %zu, expect begins with %x\n " , write, ctx.next_byte_write );
256
257
buffer_bytes += write;
257
258
assert (buffer_bytes <= chunk_size * max_chunks);
258
259
next_byte_write = ctx.next_byte_write ;
@@ -263,13 +264,14 @@ int fuzz_handle_bufq(FuzzedDataProvider *fuzz)
263
264
}
264
265
265
266
case OP_TYPE_PASS: {
266
- ssize_t op_size = fuzz->ConsumeIntegralInRange (0 , FUZZ_MAX_RW_SIZE);
267
+ size_t op_size = fuzz->ConsumeIntegralInRange (0 , FUZZ_MAX_RW_SIZE);
267
268
FV_PRINTF (verbose, " OP: pass, size %zd\n " , op_size);
268
269
struct writer_cb_ctx ctx = { .verbose = verbose, .template_buf = template_buf, .read_len = op_size, .next_byte_read = next_byte_read };
269
- ssize_t read = Curl_bufq_pass (&q, bufq_writer_cb, &ctx, &err);
270
- if (read != -1 ) {
271
- FV_PRINTF (verbose, " OP: pass, success, read %zd, expect begins with %x\n " , read, ctx.next_byte_read );
272
- buffer_bytes -= read;
270
+ size_t nread;
271
+ CURLcode result = Curl_bufq_pass (&q, bufq_writer_cb, &ctx, &nread);
272
+ if (!result) {
273
+ FV_PRINTF (verbose, " OP: pass, success, read %zu, expect begins with %x\n " , nread, ctx.next_byte_read );
274
+ buffer_bytes -= nread;
273
275
} else {
274
276
FV_PRINTF (verbose, " OP: pass, error\n " );
275
277
/* in case of -1, it may still have read something, adjust for that */
@@ -284,7 +286,7 @@ int fuzz_handle_bufq(FuzzedDataProvider *fuzz)
284
286
size_t op_size = fuzz->ConsumeIntegralInRange (0 , FUZZ_MAX_RW_SIZE);
285
287
FV_PRINTF (verbose, " OP: skip, size %zu\n " , op_size);
286
288
Curl_bufq_skip (&q, op_size);
287
- ssize_t old_buffer_bytes = buffer_bytes;
289
+ size_t old_buffer_bytes = buffer_bytes;
288
290
buffer_bytes = old_buffer_bytes > op_size ? old_buffer_bytes - op_size : 0 ;
289
291
next_byte_read += old_buffer_bytes > op_size ? op_size : old_buffer_bytes;
290
292
break ;
@@ -294,9 +296,10 @@ int fuzz_handle_bufq(FuzzedDataProvider *fuzz)
294
296
size_t op_size = fuzz->ConsumeIntegralInRange (0 , FUZZ_MAX_RW_SIZE);
295
297
FV_PRINTF (verbose, " OP: write, size %zu, begins with %x\n " , op_size, next_byte_write);
296
298
unsigned char *buf = compute_buffer (next_byte_write, template_buf);
297
- ssize_t written = Curl_bufq_write (&q, buf, op_size, &err);
298
- if (written != -1 ) {
299
- FV_PRINTF (verbose, " OP: write, success, written %zd\n " , written);
299
+ size_t written;
300
+ CURLcode result = Curl_bufq_write (&q, buf, op_size, &written);
301
+ if (!result) {
302
+ FV_PRINTF (verbose, " OP: write, success, written %zu\n " , written);
300
303
next_byte_write += written;
301
304
buffer_bytes += written;
302
305
assert (buffer_bytes <= chunk_size * max_chunks);
0 commit comments