mirror of
https://github.com/switchbrew/libnx.git
synced 2025-06-21 12:32:40 +02:00
service: Static assert arguments aren't pointers to prevent failure-to-deref
This commit is contained in:
parent
4fcdb6eb34
commit
edc000928b
@ -473,14 +473,23 @@ NX_INLINE Result serviceDispatchImpl(
|
||||
return rc;
|
||||
}
|
||||
|
||||
#define serviceMacroDetectIsSameType(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
|
||||
#define serviceMacroDetectIsPointerOrArray(p) (__builtin_classify_type(p) == 5)
|
||||
#define serviceMacroDecay(p) (&*__builtin_choose_expr(serviceMacroDetectIsPointerOrArray(p), p, NULL))
|
||||
#define serviceMacroDetectIsPointer(p) serviceMacroDetectIsSameType(p, serviceMacroDecay(p))
|
||||
|
||||
#define serviceDispatch(_s,_rid,...) \
|
||||
serviceDispatchImpl((_s),(_rid),NULL,0,NULL,0,(SfDispatchParams){ __VA_ARGS__ })
|
||||
|
||||
#define serviceDispatchIn(_s,_rid,_in,...) \
|
||||
serviceDispatchImpl((_s),(_rid),&(_in),sizeof(_in),NULL,0,(SfDispatchParams){ __VA_ARGS__ })
|
||||
({ _Static_assert(!(serviceMacroDetectIsPointer(_in))); \
|
||||
serviceDispatchImpl((_s),(_rid),&(_in),sizeof(_in),NULL,0,(SfDispatchParams){ __VA_ARGS__ }); })
|
||||
|
||||
#define serviceDispatchOut(_s,_rid,_out,...) \
|
||||
serviceDispatchImpl((_s),(_rid),NULL,0,&(_out),sizeof(_out),(SfDispatchParams){ __VA_ARGS__ })
|
||||
({ _Static_assert(!(serviceMacroDetectIsPointer(_out))); \
|
||||
serviceDispatchImpl((_s),(_rid),NULL,0,&(_out),sizeof(_out),(SfDispatchParams){ __VA_ARGS__ }); })
|
||||
|
||||
#define serviceDispatchInOut(_s,_rid,_in,_out,...) \
|
||||
serviceDispatchImpl((_s),(_rid),&(_in),sizeof(_in),&(_out),sizeof(_out),(SfDispatchParams){ __VA_ARGS__ })
|
||||
({ _Static_assert(!(serviceMacroDetectIsPointer(_in))); \
|
||||
_Static_assert(!(serviceMacroDetectIsPointer(_out))); \
|
||||
serviceDispatchImpl((_s),(_rid),&(_in),sizeof(_in),&(_out),sizeof(_out),(SfDispatchParams){ __VA_ARGS__ }); })
|
||||
|
@ -109,7 +109,7 @@ Result capscGenerateApplicationAlbumEntry(CapsApplicationAlbumEntry *appEntry, c
|
||||
Result capscSaveAlbumScreenShotFile(const CapsAlbumFileId *file_id, const void* buffer, u64 buffer_size) {
|
||||
if (hosversionBefore(2,0,0) || hosversionAtLeast(4,0,0))
|
||||
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
|
||||
return serviceDispatchIn(&g_capscSrv, 2201, file_id,
|
||||
return serviceDispatchIn(&g_capscSrv, 2201, *file_id,
|
||||
.buffer_attrs = { SfBufferAttr_HipcMapTransferAllowsNonSecure | SfBufferAttr_HipcMapAlias | SfBufferAttr_In },
|
||||
.buffers = { { buffer, buffer_size }, },
|
||||
);
|
||||
|
@ -1503,7 +1503,7 @@ Result nsCompareApplicationDeliveryInfo(const NsApplicationDeliveryInfo *info0,
|
||||
Service srv={0};
|
||||
Result rc = nsGetApplicationManagerInterface(&srv);
|
||||
|
||||
if (R_SUCCEEDED(rc)) rc = serviceDispatchOut(&srv, 2005, out,
|
||||
if (R_SUCCEEDED(rc)) rc = serviceDispatchOut(&srv, 2005, *out,
|
||||
.buffer_attrs = {
|
||||
SfBufferAttr_HipcMapAlias | SfBufferAttr_In,
|
||||
SfBufferAttr_HipcMapAlias | SfBufferAttr_In,
|
||||
@ -1710,7 +1710,7 @@ Result nsCompareSystemDeliveryInfo(const NsSystemDeliveryInfo *info0, const NsSy
|
||||
Service srv={0};
|
||||
Result rc = nsGetApplicationManagerInterface(&srv);
|
||||
|
||||
if (R_SUCCEEDED(rc)) rc = serviceDispatchOut(&srv, 2015, out,
|
||||
if (R_SUCCEEDED(rc)) rc = serviceDispatchOut(&srv, 2015, *out,
|
||||
.buffer_attrs = {
|
||||
SfBufferAttr_HipcMapAlias | SfBufferAttr_In,
|
||||
SfBufferAttr_HipcMapAlias | SfBufferAttr_In,
|
||||
|
Loading…
Reference in New Issue
Block a user