From af94c3fcbfdb76130d519a6d1c7671f017144a14 Mon Sep 17 00:00:00 2001 From: fgsch <> Date: Sat, 28 Dec 2002 10:24:09 +0000 Subject: fix calloc's. also check for errors; fixes PR/3043. --- src/usr.bin/nc/netcat.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/usr.bin/nc/netcat.c b/src/usr.bin/nc/netcat.c index 717e0377eb..8361d228ff 100644 --- a/src/usr.bin/nc/netcat.c +++ b/src/usr.bin/nc/netcat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: netcat.c,v 1.54 2002/12/13 19:53:45 aaron Exp $ */ +/* $OpenBSD: netcat.c,v 1.55 2002/12/28 10:24:09 fgsch Exp $ */ /* * Copyright (c) 2001 Eric Jackson * @@ -55,7 +55,8 @@ (sizeof(*(su)) - sizeof((su)->sun_path) + strlen((su)->sun_path)) #endif -#define PORT_MAX 65535 +#define PORT_MAX 65535 +#define PORT_MAX_LEN 6 /* Command Line Options */ int iflag; /* Interval Flag */ @@ -655,8 +656,10 @@ build_ports(char *p) /* Load ports sequentially */ for (cp = lo; cp <= hi; cp++) { - portlist[x] = calloc(1, PORT_MAX); - snprintf(portlist[x], PORT_MAX, "%d", cp); + portlist[x] = calloc(1, PORT_MAX_LEN); + if (portlist[x] == NULL) + err(1, NULL); + snprintf(portlist[x], PORT_MAX_LEN, "%d", cp); x++; } @@ -676,7 +679,9 @@ build_ports(char *p) hi = (int)strtoul(p, &endp, 10); if (hi <= 0 || hi > PORT_MAX || *endp != '\0') errx(1, "port range not valid"); - portlist[0] = calloc(1, PORT_MAX); + portlist[0] = calloc(1, PORT_MAX_LEN); + if (portlist[0] == NULL) + err(1, NULL); portlist[0] = p; } } -- cgit v1.2.3-55-g6feb