@@ -1759,16 +1759,19 @@ static __be32 nfsd4_encode_components_esc(struct xdr_stream *xdr, char sep,
1759
1759
char esc_exit )
1760
1760
{
1761
1761
__be32 * p ;
1762
- __be32 * countp ;
1762
+ __be32 pathlen ;
1763
+ int pathlen_offset ;
1763
1764
int strlen , count = 0 ;
1764
1765
char * str , * end , * next ;
1765
1766
1766
1767
dprintk ("nfsd4_encode_components(%s)\n" , components );
1768
+
1769
+ pathlen_offset = xdr -> buf -> len ;
1767
1770
p = xdr_reserve_space (xdr , 4 );
1768
1771
if (!p )
1769
1772
return nfserr_resource ;
1770
- countp = p ;
1771
- WRITE32 ( 0 ); /* We will fill this in with @count later */
1773
+ p ++ ; /* We will fill this in with @count later */
1774
+
1772
1775
end = str = components ;
1773
1776
while (* end ) {
1774
1777
bool found_esc = false;
@@ -1801,8 +1804,8 @@ static __be32 nfsd4_encode_components_esc(struct xdr_stream *xdr, char sep,
1801
1804
end ++ ;
1802
1805
str = end ;
1803
1806
}
1804
- p = countp ;
1805
- WRITE32 ( count );
1807
+ pathlen = htonl ( xdr -> buf -> len - pathlen_offset ) ;
1808
+ write_bytes_to_xdr_buf ( xdr -> buf , pathlen_offset , & pathlen , 4 );
1806
1809
return 0 ;
1807
1810
}
1808
1811
@@ -2054,7 +2057,8 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
2054
2057
struct kstatfs statfs ;
2055
2058
__be32 * p ;
2056
2059
int starting_len = xdr -> buf -> len ;
2057
- __be32 * attrlenp ;
2060
+ int attrlen_offset ;
2061
+ __be32 attrlen ;
2058
2062
u32 dummy ;
2059
2063
u64 dummy64 ;
2060
2064
u32 rdattr_err = 0 ;
@@ -2159,10 +2163,12 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
2159
2163
WRITE32 (1 );
2160
2164
WRITE32 (bmval0 );
2161
2165
}
2166
+
2167
+ attrlen_offset = xdr -> buf -> len ;
2162
2168
p = xdr_reserve_space (xdr , 4 );
2163
2169
if (!p )
2164
2170
goto out_resource ;
2165
- attrlenp = p ++ ; /* to be backfilled later */
2171
+ p ++ ; /* to be backfilled later */
2166
2172
2167
2173
if (bmval0 & FATTR4_WORD0_SUPPORTED_ATTRS ) {
2168
2174
u32 word0 = nfsd_suppattrs0 (minorversion );
@@ -2534,7 +2540,8 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
2534
2540
WRITE32 (NFSD_SUPPATTR_EXCLCREAT_WORD2 );
2535
2541
}
2536
2542
2537
- * attrlenp = htonl ((char * )xdr -> p - (char * )attrlenp - 4 );
2543
+ attrlen = htonl (xdr -> buf -> len - attrlen_offset - 4 );
2544
+ write_bytes_to_xdr_buf (xdr -> buf , attrlen_offset , & attrlen , 4 );
2538
2545
status = nfs_ok ;
2539
2546
2540
2547
out :
@@ -3664,15 +3671,16 @@ __be32 nfsd4_check_resp_size(struct nfsd4_compoundres *resp, u32 pad)
3664
3671
void
3665
3672
nfsd4_encode_operation (struct nfsd4_compoundres * resp , struct nfsd4_op * op )
3666
3673
{
3674
+ struct xdr_stream * xdr = & resp -> xdr ;
3667
3675
struct nfs4_stateowner * so = resp -> cstate .replay_owner ;
3668
3676
struct svc_rqst * rqstp = resp -> rqstp ;
3669
- __be32 * statp ;
3677
+ int post_err_offset ;
3670
3678
nfsd4_enc encoder ;
3671
3679
__be32 * p ;
3672
3680
3673
3681
RESERVE_SPACE (8 );
3674
3682
WRITE32 (op -> opnum );
3675
- statp = p ++ ; /* to be backfilled at the end */
3683
+ post_err_offset = xdr -> buf -> len ;
3676
3684
3677
3685
if (op -> opnum == OP_ILLEGAL )
3678
3686
goto status ;
@@ -3698,20 +3706,19 @@ nfsd4_encode_operation(struct nfsd4_compoundres *resp, struct nfsd4_op *op)
3698
3706
* bug if we had to do this on a non-idempotent op:
3699
3707
*/
3700
3708
warn_on_nonidempotent_op (op );
3701
- resp -> xdr . p = statp + 1 ;
3709
+ xdr_truncate_encode ( xdr , post_err_offset ) ;
3702
3710
}
3703
3711
if (so ) {
3712
+ int len = xdr -> buf -> len - post_err_offset ;
3713
+
3704
3714
so -> so_replay .rp_status = op -> status ;
3705
- so -> so_replay .rp_buflen = ( char * ) resp -> xdr . p
3706
- - ( char * )( statp + 1 );
3707
- memcpy ( so -> so_replay .rp_buf , statp + 1 , so -> so_replay . rp_buflen );
3715
+ so -> so_replay .rp_buflen = len ;
3716
+ read_bytes_from_xdr_buf ( xdr -> buf , post_err_offset ,
3717
+ so -> so_replay .rp_buf , len );
3708
3718
}
3709
3719
status :
3710
- /*
3711
- * Note: We write the status directly, instead of using WRITE32(),
3712
- * since it is already in network byte order.
3713
- */
3714
- * statp = op -> status ;
3720
+ /* Note that op->status is already in network byte order: */
3721
+ write_bytes_to_xdr_buf (xdr -> buf , post_err_offset - 4 , & op -> status , 4 );
3715
3722
}
3716
3723
3717
3724
/*
0 commit comments