file_systems/nfs: Fix SMAP violations

* Try to return relevant errors when we can.
* The style on these needs cleaned up badly.
* I don't want the fix to be lost in style changes.

Change-Id: I8a1661385fbeb8eec86a2c15828b449980050a78
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3386
Reviewed-by: Jérôme Duval <[email protected]>
This commit is contained in:
Alexander von Gluck IV
2020-11-25 19:32:33 +00:00
committed by Alex von Gluck IV
parent 9d84226fcd
commit f566cf181a
4 changed files with 46 additions and 16 deletions
@@ -2,6 +2,9 @@
#include <malloc.h> #include <malloc.h>
#include <string.h> #include <string.h>
#include <ByteOrder.h> #include <ByteOrder.h>
#include <KernelExport.h>
#include "nfs.h"
extern void extern void
XDRInPacketInit(struct XDRInPacket *packet) XDRInPacketInit(struct XDRInPacket *packet)
@@ -26,19 +29,23 @@ XDRInPacketGetInt32(struct XDRInPacket *packet)
return val; return val;
} }
extern void extern int32
XDRInPacketGetFixed(struct XDRInPacket *packet, void *buffer, size_t len) XDRInPacketGetFixed(struct XDRInPacket *packet, void *buffer, size_t len)
{ {
memcpy (buffer,&packet->fBuffer[packet->fOffset],len); if (user_memcpy(buffer, &packet->fBuffer[packet->fOffset], len)
packet->fOffset+=(len+3)&~3; != B_OK) {
return NFSERR_IO;
}
packet->fOffset += (len + 3) & ~3;
return NFS_OK;
} }
extern size_t extern size_t
XDRInPacketGetDynamic(struct XDRInPacket *packet, void *buffer) XDRInPacketGetDynamic(struct XDRInPacket *packet, void *buffer)
{ {
size_t size=XDRInPacketGetInt32(packet); size_t size=XDRInPacketGetInt32(packet);
XDRInPacketGetFixed (packet,buffer,size); XDRInPacketGetFixed(packet,buffer,size);
return size; return size;
} }
@@ -48,7 +55,7 @@ XDRInPacketGetString(struct XDRInPacket *packet)
int32 size=XDRInPacketGetInt32(packet); int32 size=XDRInPacketGetInt32(packet);
char *string=(char *)malloc(size+1); char *string=(char *)malloc(size+1);
string[size]=0; string[size]=0;
XDRInPacketGetFixed (packet,string,size); XDRInPacketGetFixed(packet,string,size);
return string; return string;
} }
@@ -13,7 +13,8 @@ struct XDRInPacket
void XDRInPacketInit (struct XDRInPacket *packet); void XDRInPacketInit (struct XDRInPacket *packet);
void XDRInPacketDestroy (struct XDRInPacket *packet); void XDRInPacketDestroy (struct XDRInPacket *packet);
int32 XDRInPacketGetInt32 (struct XDRInPacket *packet); int32 XDRInPacketGetInt32 (struct XDRInPacket *packet);
void XDRInPacketGetFixed (struct XDRInPacket *packet, void *buffer, size_t len); int32 XDRInPacketGetFixed (struct XDRInPacket *packet, void *buffer,
size_t len);
size_t XDRInPacketGetDynamic (struct XDRInPacket *packet, void *buffer); size_t XDRInPacketGetDynamic (struct XDRInPacket *packet, void *buffer);
char *XDRInPacketGetString (struct XDRInPacket *packet); char *XDRInPacketGetString (struct XDRInPacket *packet);
void XDRInPacketSetTo (struct XDRInPacket *packet, uint8 *buffer, size_t offset); void XDRInPacketSetTo (struct XDRInPacket *packet, uint8 *buffer, size_t offset);
+2 -2
View File
@@ -4,8 +4,8 @@
#include <SupportDefs.h> #include <SupportDefs.h>
const int32 NFS_VERSION=2; #define NFS_VERSION 2
const int32 NFS_PROGRAM=100003; #define NFS_PROGRAM 100003
typedef enum nfs_stat typedef enum nfs_stat
{ {
@@ -484,17 +484,18 @@ nfs_mount(fs_nspace *ns, const char *path, nfs_fhandle *fhandle)
fhstatus = XDRInPacketGetInt32(&reply); fhstatus = XDRInPacketGetInt32(&reply);
if (fhstatus != 0) { if (fhstatus != NFS_OK) {
XDRInPacketDestroy(&reply); XDRInPacketDestroy(&reply);
XDROutPacketDestroy(&call); XDROutPacketDestroy(&call);
return map_nfs_to_system_error(fhstatus); return map_nfs_to_system_error(fhstatus);
} }
XDRInPacketGetFixed(&reply, fhandle->opaque, NFS_FHSIZE); fhstatus = XDRInPacketGetFixed(&reply, fhandle->opaque, NFS_FHSIZE);
XDRInPacketDestroy(&reply); XDRInPacketDestroy(&reply);
XDROutPacketDestroy(&call); XDROutPacketDestroy(&call);
return B_OK;
return map_nfs_to_system_error(fhstatus);
} }
@@ -538,7 +539,13 @@ nfs_lookup (fs_nspace *ns, const nfs_fhandle *dir, const char *filename,
return map_nfs_to_system_error(status); return map_nfs_to_system_error(status);
} }
XDRInPacketGetFixed(&reply, fhandle->opaque, NFS_FHSIZE); status = XDRInPacketGetFixed(&reply, fhandle->opaque, NFS_FHSIZE);
if (status != NFS_OK) {
XDRInPacketDestroy(&reply);
XDROutPacketDestroy(&call);
return map_nfs_to_system_error(status);
}
if (st) if (st)
get_nfs_attr(&reply, st); get_nfs_attr(&reply, st);
@@ -1002,7 +1009,11 @@ fs_readdir(fs_volume *_volume, fs_vnode *_node, void *_cookie,
vnid=XDRInPacketGetInt32(&reply); vnid=XDRInPacketGetInt32(&reply);
filename=XDRInPacketGetString(&reply); filename=XDRInPacketGetString(&reply);
XDRInPacketGetFixed(&reply, newCookie.opaque, NFS_COOKIESIZE); status = XDRInPacketGetFixed(&reply, newCookie.opaque,
NFS_COOKIESIZE);
if (status != NFS_OK)
return map_nfs_to_system_error(status);
//if (strcmp(".",filename)&&strcmp("..",filename)) //if (strcmp(".",filename)&&strcmp("..",filename))
//if ((ns->rootid != node->vnid) || (strcmp(".",filename)&&strcmp("..",filename))) //if ((ns->rootid != node->vnid) || (strcmp(".",filename)&&strcmp("..",filename)))
@@ -1810,7 +1821,13 @@ fs_create(fs_volume *_volume, fs_vnode *_dir, const char *name, int omode,
return map_nfs_to_system_error(status); return map_nfs_to_system_error(status);
} }
XDRInPacketGetFixed(&reply, fhandle.opaque, NFS_FHSIZE); status = XDRInPacketGetFixed(&reply, fhandle.opaque, NFS_FHSIZE);
if (status != NFS_OK) {
XDRInPacketDestroy(&reply);
XDROutPacketDestroy(&call);
return map_nfs_to_system_error(status);
}
get_nfs_attr(&reply,&st); get_nfs_attr(&reply,&st);
@@ -2041,7 +2058,12 @@ fs_mkdir(fs_volume *_volume, fs_vnode *_dir, const char *name, int perms)
return map_nfs_to_system_error(status); return map_nfs_to_system_error(status);
} }
XDRInPacketGetFixed(&reply, fhandle.opaque, NFS_FHSIZE); status = XDRInPacketGetFixed(&reply, fhandle.opaque, NFS_FHSIZE);
if (status != NFS_OK) {
XDROutPacketDestroy(&call);
return map_nfs_to_system_error(status);
}
get_nfs_attr(&reply, &st); get_nfs_attr(&reply, &st);