diff options
author | Allan Stephens <allan.stephens@windriver.com> | 2006-06-26 02:49:06 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2006-06-26 02:49:06 -0400 |
commit | 51f9cc1ff8aa0866ff8fb3c06be4c64b5edbb2e8 (patch) | |
tree | ba3bfa86415fb9afa88e764672beb6fb9014b231 /net | |
parent | a3b0a5a9d004002a9cf9cf7a9d10cf1447a73d2b (diff) |
[TIPC]: Optimized argument validation done by connect().
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
Signed-off-by: Per Liden <per.liden@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r-- | net/tipc/socket.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/net/tipc/socket.c b/net/tipc/socket.c index 6d4d2b0063aa..32d778448a00 100644 --- a/net/tipc/socket.c +++ b/net/tipc/socket.c | |||
@@ -455,7 +455,8 @@ static int send_msg(struct kiocb *iocb, struct socket *sock, | |||
455 | 455 | ||
456 | if (unlikely(!dest)) | 456 | if (unlikely(!dest)) |
457 | return -EDESTADDRREQ; | 457 | return -EDESTADDRREQ; |
458 | if (unlikely(dest->family != AF_TIPC)) | 458 | if (unlikely((m->msg_namelen < sizeof(*dest)) || |
459 | (dest->family != AF_TIPC))) | ||
459 | return -EINVAL; | 460 | return -EINVAL; |
460 | 461 | ||
461 | needs_conn = (sock->state != SS_READY); | 462 | needs_conn = (sock->state != SS_READY); |
@@ -1245,7 +1246,8 @@ static int connect(struct socket *sock, struct sockaddr *dest, int destlen, | |||
1245 | if (sock->state == SS_READY) | 1246 | if (sock->state == SS_READY) |
1246 | return -EOPNOTSUPP; | 1247 | return -EOPNOTSUPP; |
1247 | 1248 | ||
1248 | /* MOVE THE REST OF THIS ERROR CHECKING TO send_msg()? */ | 1249 | /* Issue Posix-compliant error code if socket is in the wrong state */ |
1250 | |||
1249 | if (sock->state == SS_LISTENING) | 1251 | if (sock->state == SS_LISTENING) |
1250 | return -EOPNOTSUPP; | 1252 | return -EOPNOTSUPP; |
1251 | if (sock->state == SS_CONNECTING) | 1253 | if (sock->state == SS_CONNECTING) |
@@ -1253,13 +1255,20 @@ static int connect(struct socket *sock, struct sockaddr *dest, int destlen, | |||
1253 | if (sock->state != SS_UNCONNECTED) | 1255 | if (sock->state != SS_UNCONNECTED) |
1254 | return -EISCONN; | 1256 | return -EISCONN; |
1255 | 1257 | ||
1256 | if ((destlen < sizeof(*dst)) || (dst->family != AF_TIPC) || | 1258 | /* |
1257 | ((dst->addrtype != TIPC_ADDR_NAME) && (dst->addrtype != TIPC_ADDR_ID))) | 1259 | * Reject connection attempt using multicast address |
1260 | * | ||
1261 | * Note: send_msg() validates the rest of the address fields, | ||
1262 | * so there's no need to do it here | ||
1263 | */ | ||
1264 | |||
1265 | if (dst->addrtype == TIPC_ADDR_MCAST) | ||
1258 | return -EINVAL; | 1266 | return -EINVAL; |
1259 | 1267 | ||
1260 | /* Send a 'SYN-' to destination */ | 1268 | /* Send a 'SYN-' to destination */ |
1261 | 1269 | ||
1262 | m.msg_name = dest; | 1270 | m.msg_name = dest; |
1271 | m.msg_namelen = destlen; | ||
1263 | if ((res = send_msg(NULL, sock, &m, 0)) < 0) { | 1272 | if ((res = send_msg(NULL, sock, &m, 0)) < 0) { |
1264 | sock->state = SS_DISCONNECTING; | 1273 | sock->state = SS_DISCONNECTING; |
1265 | return res; | 1274 | return res; |