Skip to content

Commit d37c068

Browse files
tiranvstinner
authored andcommitted
Add sockaddr_alg to sock_addr_t (#234)
sock_addr_t is used to define the minimum size of any socket address on the stack. Let's make sure that an AF_ALG address always fits. Coverity complains because in theory, AF_ALG might be larger than any of the other structs. In practice it already fits. Closes Coverity CID 1398948, 1398949, 1398950 Signed-off-by: Christian Heimes <[email protected]>
1 parent 03f68b6 commit d37c068

File tree

2 files changed

+34
-30
lines changed

2 files changed

+34
-30
lines changed

Modules/socketmodule.c

-30
Original file line numberDiff line numberDiff line change
@@ -288,36 +288,6 @@ if_indextoname(index) -- return the corresponding interface name\n\
288288
#include <net/if.h>
289289
#endif
290290

291-
#ifdef HAVE_SOCKADDR_ALG
292-
#include <linux/if_alg.h>
293-
#ifndef AF_ALG
294-
#define AF_ALG 38
295-
#endif
296-
#ifndef SOL_ALG
297-
#define SOL_ALG 279
298-
#endif
299-
300-
/* Linux 3.19 */
301-
#ifndef ALG_SET_AEAD_ASSOCLEN
302-
#define ALG_SET_AEAD_ASSOCLEN 4
303-
#endif
304-
#ifndef ALG_SET_AEAD_AUTHSIZE
305-
#define ALG_SET_AEAD_AUTHSIZE 5
306-
#endif
307-
/* Linux 4.8 */
308-
#ifndef ALG_SET_PUBKEY
309-
#define ALG_SET_PUBKEY 6
310-
#endif
311-
312-
#ifndef ALG_OP_SIGN
313-
#define ALG_OP_SIGN 2
314-
#endif
315-
#ifndef ALG_OP_VERIFY
316-
#define ALG_OP_VERIFY 3
317-
#endif
318-
319-
#endif /* HAVE_SOCKADDR_ALG */
320-
321291
/* Generic socket object definitions and includes */
322292
#define PySocket_BUILDING_SOCKET
323293
#include "socketmodule.h"

Modules/socketmodule.h

+34
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,37 @@ typedef int socklen_t;
9898
#include <sys/kern_control.h>
9999
#endif
100100

101+
#ifdef HAVE_SOCKADDR_ALG
102+
#include <linux/if_alg.h>
103+
#ifndef AF_ALG
104+
#define AF_ALG 38
105+
#endif
106+
#ifndef SOL_ALG
107+
#define SOL_ALG 279
108+
#endif
109+
110+
/* Linux 3.19 */
111+
#ifndef ALG_SET_AEAD_ASSOCLEN
112+
#define ALG_SET_AEAD_ASSOCLEN 4
113+
#endif
114+
#ifndef ALG_SET_AEAD_AUTHSIZE
115+
#define ALG_SET_AEAD_AUTHSIZE 5
116+
#endif
117+
/* Linux 4.8 */
118+
#ifndef ALG_SET_PUBKEY
119+
#define ALG_SET_PUBKEY 6
120+
#endif
121+
122+
#ifndef ALG_OP_SIGN
123+
#define ALG_OP_SIGN 2
124+
#endif
125+
#ifndef ALG_OP_VERIFY
126+
#define ALG_OP_VERIFY 3
127+
#endif
128+
129+
#endif /* HAVE_SOCKADDR_ALG */
130+
131+
101132
#ifndef Py__SOCKET_H
102133
#define Py__SOCKET_H
103134
#ifdef __cplusplus
@@ -159,6 +190,9 @@ typedef union sock_addr {
159190
#ifdef HAVE_SYS_KERN_CONTROL_H
160191
struct sockaddr_ctl ctl;
161192
#endif
193+
#ifdef HAVE_SOCKADDR_ALG
194+
struct sockaddr_alg alg;
195+
#endif
162196
} sock_addr_t;
163197

164198
/* The object holding a socket. It holds some extra information,

0 commit comments

Comments
 (0)