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/+/3396
Reviewed-by: Alex von Gluck IV <kallisti5@unixzen.com>
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>
Diff
src/add-ons/kernel/file_systems/nfs/XDRInPacket.c | 19 ++++++++++++++++---
src/add-ons/kernel/file_systems/nfs/XDRInPacket.h | 3 ++-
src/add-ons/kernel/file_systems/nfs/nfs.h | 4 ++--
src/add-ons/kernel/file_systems/nfs/nfs_add_on.c | 36 ++++++++++++++++++++++++++++++++----
4 files changed, 46 insertions(+), 16 deletions(-)
@@ -1,8 +1,11 @@
#include "XDRInPacket.h"
#include <malloc.h>
#include <string.h>
#include <ByteOrder.h>
#include <KernelExport.h>
#include "nfs.h"
extern void
XDRInPacketInit(struct XDRInPacket *packet)
{
@@ -26,19 +29,23 @@
return val;
}
extern void
extern int32
XDRInPacketGetFixed(struct XDRInPacket *packet, void *buffer, size_t len)
{
memcpy (buffer,&packet->fBuffer[packet->fOffset],len);
packet->fOffset+=(len+3)&~3;
if (user_memcpy(buffer, &packet->fBuffer[packet->fOffset], len)
!= B_OK) {
return NFSERR_IO;
}
packet->fOffset += (len + 3) & ~3;
return NFS_OK;
}
extern size_t
XDRInPacketGetDynamic(struct XDRInPacket *packet, void *buffer)
{
size_t size=XDRInPacketGetInt32(packet);
XDRInPacketGetFixed (packet,buffer,size);
XDRInPacketGetFixed(packet,buffer,size);
return size;
}
@@ -48,7 +55,7 @@
int32 size=XDRInPacketGetInt32(packet);
char *string=(char *)malloc(size+1);
string[size]=0;
XDRInPacketGetFixed (packet,string,size);
XDRInPacketGetFixed(packet,string,size);
return string;
}
@@ -13,7 +13,8 @@
void XDRInPacketInit (struct XDRInPacket *packet);
void XDRInPacketDestroy (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);
char *XDRInPacketGetString (struct XDRInPacket *packet);
void XDRInPacketSetTo (struct XDRInPacket *packet, uint8 *buffer, size_t offset);
@@ -1,11 +1,11 @@
#ifndef _NFS_H
#define _NFS_H
#include <SupportDefs.h>
const int32 NFS_VERSION=2;
const int32 NFS_PROGRAM=100003;
#define NFS_VERSION 2
#define NFS_PROGRAM 100003
typedef enum nfs_stat
{
@@ -484,17 +484,18 @@
fhstatus = XDRInPacketGetInt32(&reply);
if (fhstatus != 0) {
if (fhstatus != NFS_OK) {
XDRInPacketDestroy(&reply);
XDROutPacketDestroy(&call);
return map_nfs_to_system_error(fhstatus);
}
XDRInPacketGetFixed(&reply, fhandle->opaque, NFS_FHSIZE);
fhstatus = XDRInPacketGetFixed(&reply, fhandle->opaque, NFS_FHSIZE);
XDRInPacketDestroy(&reply);
XDROutPacketDestroy(&call);
return B_OK;
return map_nfs_to_system_error(fhstatus);
}
@@ -538,7 +539,13 @@
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)
get_nfs_attr(&reply, st);
@@ -1002,8 +1009,12 @@
vnid=XDRInPacketGetInt32(&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 (conf_ls_root_parent
@@ -1809,8 +1820,14 @@
XDROutPacketDestroy(&call);
return map_nfs_to_system_error(status);
}
status = XDRInPacketGetFixed(&reply, fhandle.opaque, NFS_FHSIZE);
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);
@@ -2041,7 +2058,12 @@
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);