diff options
author | Simon Rettberg | 2020-10-08 12:24:06 +0200 |
---|---|---|
committer | Simon Rettberg | 2020-10-08 12:24:06 +0200 |
commit | b79d2f21e8f9c0d31568e82b77004a9bbe3b8be3 (patch) | |
tree | dfe3e688b35372711c0a4637f27d229ad04c05dc /src/rpc.c | |
parent | Tweak session killing, don't try login process right away (diff) | |
download | idle-daemon-b79d2f21e8f9c0d31568e82b77004a9bbe3b8be3.tar.gz idle-daemon-b79d2f21e8f9c0d31568e82b77004a9bbe3b8be3.tar.xz idle-daemon-b79d2f21e8f9c0d31568e82b77004a9bbe3b8be3.zip |
Fix potential strcmp() overflow, better packed struct for pipe
Diffstat (limited to 'src/rpc.c')
-rw-r--r-- | src/rpc.c | 13 |
1 files changed, 7 insertions, 6 deletions
@@ -18,15 +18,16 @@ #define SOCKPATH "/run/idle-daemon" -#pragma pack(1) -static struct { - int read; - int write; +static union { + struct __attribute__((packed)) { + int read; + int write; + }; + int array[2]; } rpcPipe = { .read = -1, .write = -1, }; -#pragma pack(0) _Static_assert( sizeof(rpcPipe) == ( sizeof(int) * 2 ), "Structsize mismatch" ); @@ -56,7 +57,7 @@ int rpc_open( void ) return -1; } if ( rpcPipe.write == -1 && rpcPipe.read == -1 ) { - if ( pipe2( (int*)&rpcPipe, O_DIRECT ) == -1 ) { + if ( pipe2( rpcPipe.array, O_DIRECT ) == -1 ) { perror( "Cannot create local RPC pipe" ); } else { // Read end nonblocking |