mirror of
https://github.com/Fishwaldo/linux-bl808.git
synced 2025-06-17 20:25:19 +00:00
rpc: define xdr_restrict_buflen
With this xdr_reserve_space can help us enforce various limits. Signed-off-by: J. Bruce Fields <bfields@redhat.com>
This commit is contained in:
parent
30596768b3
commit
db3f58a95b
2 changed files with 30 additions and 0 deletions
|
@ -217,6 +217,7 @@ extern void xdr_init_encode(struct xdr_stream *xdr, struct xdr_buf *buf, __be32
|
||||||
extern __be32 *xdr_reserve_space(struct xdr_stream *xdr, size_t nbytes);
|
extern __be32 *xdr_reserve_space(struct xdr_stream *xdr, size_t nbytes);
|
||||||
extern void xdr_commit_encode(struct xdr_stream *xdr);
|
extern void xdr_commit_encode(struct xdr_stream *xdr);
|
||||||
extern void xdr_truncate_encode(struct xdr_stream *xdr, size_t len);
|
extern void xdr_truncate_encode(struct xdr_stream *xdr, size_t len);
|
||||||
|
extern int xdr_restrict_buflen(struct xdr_stream *xdr, int newbuflen);
|
||||||
extern void xdr_write_pages(struct xdr_stream *xdr, struct page **pages,
|
extern void xdr_write_pages(struct xdr_stream *xdr, struct page **pages,
|
||||||
unsigned int base, unsigned int len);
|
unsigned int base, unsigned int len);
|
||||||
extern unsigned int xdr_stream_pos(const struct xdr_stream *xdr);
|
extern unsigned int xdr_stream_pos(const struct xdr_stream *xdr);
|
||||||
|
|
|
@ -648,6 +648,35 @@ void xdr_truncate_encode(struct xdr_stream *xdr, size_t len)
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(xdr_truncate_encode);
|
EXPORT_SYMBOL(xdr_truncate_encode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* xdr_restrict_buflen - decrease available buffer space
|
||||||
|
* @xdr: pointer to xdr_stream
|
||||||
|
* @newbuflen: new maximum number of bytes available
|
||||||
|
*
|
||||||
|
* Adjust our idea of how much space is available in the buffer.
|
||||||
|
* If we've already used too much space in the buffer, returns -1.
|
||||||
|
* If the available space is already smaller than newbuflen, returns 0
|
||||||
|
* and does nothing. Otherwise, adjusts xdr->buf->buflen to newbuflen
|
||||||
|
* and ensures xdr->end is set at most offset newbuflen from the start
|
||||||
|
* of the buffer.
|
||||||
|
*/
|
||||||
|
int xdr_restrict_buflen(struct xdr_stream *xdr, int newbuflen)
|
||||||
|
{
|
||||||
|
struct xdr_buf *buf = xdr->buf;
|
||||||
|
int left_in_this_buf = (void *)xdr->end - (void *)xdr->p;
|
||||||
|
int end_offset = buf->len + left_in_this_buf;
|
||||||
|
|
||||||
|
if (newbuflen < 0 || newbuflen < buf->len)
|
||||||
|
return -1;
|
||||||
|
if (newbuflen > buf->buflen)
|
||||||
|
return 0;
|
||||||
|
if (newbuflen < end_offset)
|
||||||
|
xdr->end = (void *)xdr->end + newbuflen - end_offset;
|
||||||
|
buf->buflen = newbuflen;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL(xdr_restrict_buflen);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* xdr_write_pages - Insert a list of pages into an XDR buffer for sending
|
* xdr_write_pages - Insert a list of pages into an XDR buffer for sending
|
||||||
* @xdr: pointer to xdr_stream
|
* @xdr: pointer to xdr_stream
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue