Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/external/bsd/blacklist/lib Fix bug with 0 length sockets; ab...
details: https://anonhg.NetBSD.org/src/rev/81f4a9f125f3
branches: trunk
changeset: 335749:81f4a9f125f3
user: christos <christos%NetBSD.org@localhost>
date: Thu Jan 22 20:11:33 2015 +0000
description:
Fix bug with 0 length sockets; abstract get socket data function out.
diffstat:
external/bsd/blacklist/lib/bl.c | 81 ++++++++++++++++++++++++----------------
1 files changed, 48 insertions(+), 33 deletions(-)
diffs (117 lines):
diff -r 5675bce4cc8a -r 81f4a9f125f3 external/bsd/blacklist/lib/bl.c
--- a/external/bsd/blacklist/lib/bl.c Thu Jan 22 20:01:22 2015 +0000
+++ b/external/bsd/blacklist/lib/bl.c Thu Jan 22 20:11:33 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bl.c,v 1.21 2015/01/22 18:43:29 christos Exp $ */
+/* $NetBSD: bl.c,v 1.22 2015/01/22 20:11:33 christos Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
#endif
#include <sys/cdefs.h>
-__RCSID("$NetBSD: bl.c,v 1.21 2015/01/22 18:43:29 christos Exp $");
+__RCSID("$NetBSD: bl.c,v 1.22 2015/01/22 20:11:33 christos Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -272,6 +272,50 @@
free(b);
}
+static int
+bl_getsock(bl_t b, struct sockaddr_storage *ss, const struct sockaddr *sa,
+ socklen_t slen, const char *ctx)
+{
+ uint8_t family;
+
+ memset(ss, 0, sizeof(*ss));
+
+ switch (slen) {
+ case 0:
+ return 0;
+ case sizeof(struct sockaddr_in):
+ family = AF_INET;
+ break;
+ case sizeof(struct sockaddr_in6):
+ family = AF_INET6;
+ break;
+ default:
+ bl_log(b->b_fun, LOG_ERR, "%s: invalid socket len %u (%s)",
+ __func__, (unsigned)slen, ctx);
+ errno = EINVAL;
+ return -1;
+ }
+
+ memcpy(ss, sa, slen);
+
+ if (ss->ss_family != family) {
+ bl_log(b->b_fun, LOG_INFO,
+ "%s: correcting socket family %d to %d (%s)",
+ __func__, ss->ss_family, family, ctx);
+ ss->ss_family = family;
+ }
+
+#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
+ if (ss->ss_len != slen) {
+ bl_log(b->b_fun, LOG_INFO,
+ "%s: correcting socket len %u to %u (%s)",
+ __func__, ss->ss_len, (unsigned)slen, ctx);
+ ss->ss_len = (uint8_t)slen;
+ }
+#endif
+ return 0;
+}
+
int
bl_send(bl_t b, bl_type_t e, int pfd, const struct sockaddr *sa,
socklen_t slen, const char *ctx)
@@ -288,7 +332,6 @@
char buf[512];
} ub;
size_t ctxlen, tried;
- uint8_t family;
#define NTRIES 5
ctxlen = strlen(ctx);
@@ -301,37 +344,9 @@
ub.bl.bl_version = BL_VERSION;
ub.bl.bl_type = (uint32_t)e;
- switch (slen) {
- case sizeof(struct sockaddr_in):
- family = AF_INET;
- break;
- case sizeof(struct sockaddr_in6):
- family = AF_INET6;
- break;
- default:
- bl_log(b->b_fun, LOG_ERR, "%s: invalid socket len %u (%s)",
- __func__, (unsigned)slen, ctx);
- return EINVAL;
- }
-
- memset(&ub.bl.bl_ss, 0, sizeof(ub.bl.bl_ss));
- memcpy(&ub.bl.bl_ss, sa, slen);
+ if (bl_getsock(b, &ub.bl.bl_ss, sa, slen, ctx) == -1)
+ return -1;
- if (ub.bl.bl_ss.ss_family != family) {
- bl_log(b->b_fun, LOG_INFO,
- "%s: correcting socket family %d to %d (%s)",
- __func__, ub.bl.bl_ss.ss_family, family, ctx);
- ub.bl.bl_ss.ss_family = family;
- }
-
-#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
- if (ub.bl.bl_ss.ss_len != slen) {
- bl_log(b->b_fun, LOG_INFO,
- "%s: correcting socket len %u to %u (%s)",
- __func__, ub.bl.bl_ss.ss_len, (unsigned)slen, ctx);
- ub.bl.bl_ss.ss_len = (uint8_t)slen;
- }
-#endif
ub.bl.bl_salen = slen;
memcpy(ub.bl.bl_data, ctx, ctxlen);
Home |
Main Index |
Thread Index |
Old Index