buse.c: add assertions to avoid null function ptrs

This commit is contained in:
Pete Nelson 2013-06-27 16:51:07 -04:00
parent e4fd3b729f
commit 6ba3d26042
1 changed files with 5 additions and 0 deletions

5
buse.c
View File

@ -136,6 +136,7 @@ int buse_main(const char* dev_file, const struct buse_operations *aop, void *use
*/
case NBD_CMD_READ:
fprintf(stderr, "Request for read of size %d\n", len);
assert(aop->read);
chunk = malloc(len);
reply.error = aop->read(chunk, len, from, userdata);
write_all(sk, (char*)&reply, sizeof(struct nbd_reply));
@ -145,6 +146,7 @@ int buse_main(const char* dev_file, const struct buse_operations *aop, void *use
break;
case NBD_CMD_WRITE:
fprintf(stderr, "Request for write of size %d\n", len);
assert(aop->write);
chunk = malloc(len);
read_all(sk, chunk, len);
reply.error = aop->write(chunk, len, from, userdata);
@ -153,16 +155,19 @@ int buse_main(const char* dev_file, const struct buse_operations *aop, void *use
break;
case NBD_CMD_DISC:
/* Handle a disconnect request. */
assert(aop->disc);
aop->disc(userdata);
return 0;
#if defined NBD_CMD_FLUSH
case NBD_CMD_FLUSH:
assert(aop->flush);
reply.error = aop->flush(userdata);
write_all(sk, (char*)&reply, sizeof(struct nbd_reply));
break;
#endif
#if defined NBD_CMD_TRIM
case NBD_CMD_TRIM:
assert(aop->trim);
reply.error = aop->trim(from, len, userdata);
write_all(sk, (char*)&reply, sizeof(struct nbd_reply));
break;