diff options
Diffstat (limited to 'usr.sbin')
25 files changed, 545 insertions, 113 deletions
diff --git a/usr.sbin/acpi/acpidb/acpidb.c b/usr.sbin/acpi/acpidb/acpidb.c index b3d0021..7f4e49f 100644 --- a/usr.sbin/acpi/acpidb/acpidb.c +++ b/usr.sbin/acpi/acpidb/acpidb.c @@ -383,8 +383,7 @@ load_dsdt(const char *dsdtfile) char filetmp[PATH_MAX]; u_int8_t *code; struct stat sb; - int fd, fd2; - int error; + int dounlink, error, fd; fd = open(dsdtfile, O_RDONLY, 0); if (fd == -1) { @@ -397,11 +396,13 @@ load_dsdt(const char *dsdtfile) return (-1); } code = mmap(NULL, (size_t)sb.st_size, PROT_READ, MAP_PRIVATE, fd, (off_t)0); + close(fd); if (code == NULL) { perror("mmap"); return (-1); } if ((error = AcpiInitializeSubsystem()) != AE_OK) { + munmap(code, (size_t)sb.st_size); return (-1); } @@ -409,21 +410,30 @@ load_dsdt(const char *dsdtfile) * make sure DSDT data contains table header or not. */ if (strncmp((char *)code, "DSDT", 4) == 0) { - strncpy(filetmp, dsdtfile, sizeof(filetmp)); + dounlink = 0; + strlcpy(filetmp, dsdtfile, sizeof(filetmp)); } else { + dounlink = 1; mode_t mode = (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); dummy_dsdt_table.Length = sizeof(ACPI_TABLE_HEADER) + sb.st_size; - snprintf(filetmp, sizeof(filetmp), "%s.tmp", dsdtfile); - fd2 = open(filetmp, O_WRONLY | O_CREAT | O_TRUNC, mode); - if (fd2 == -1) { + if ((size_t)snprintf(filetmp, sizeof(filetmp), "%s.tmp", + dsdtfile) > sizeof(filetmp) - 1) { + fprintf(stderr, "file name too long\n"); + munmap(code, (size_t)sb.st_size); + return (-1); + } + fd = open(filetmp, O_WRONLY | O_CREAT | O_TRUNC, mode); + if (fd == -1) { perror("open"); + munmap(code, (size_t)sb.st_size); return (-1); } - write(fd2, &dummy_dsdt_table, sizeof(ACPI_TABLE_HEADER)); + write(fd, &dummy_dsdt_table, sizeof(ACPI_TABLE_HEADER)); - write(fd2, code, sb.st_size); - close(fd2); + write(fd, code, sb.st_size); + close(fd); } + munmap(code, (size_t)sb.st_size); /* * Install the virtual machine version of address space handlers. @@ -484,7 +494,7 @@ load_dsdt(const char *dsdtfile) AcpiGbl_DebuggerConfiguration = 0; AcpiDbUserCommands(':', NULL); - if (strcmp(dsdtfile, filetmp) != 0) { + if (dounlink) { unlink(filetmp); } diff --git a/usr.sbin/acpi/acpidump/acpi.c b/usr.sbin/acpi/acpidump/acpi.c index 3c2b302..44f8dca 100644 --- a/usr.sbin/acpi/acpidump/acpi.c +++ b/usr.sbin/acpi/acpidump/acpi.c @@ -1465,27 +1465,34 @@ dsdt_save_file(char *outfile, ACPI_TABLE_HEADER *rsdt, ACPI_TABLE_HEADER *dsdp) void aml_disassemble(ACPI_TABLE_HEADER *rsdt, ACPI_TABLE_HEADER *dsdp) { - char buf[PATH_MAX], tmpstr[PATH_MAX]; + char buf[PATH_MAX], tmpstr[PATH_MAX], wrkdir[PATH_MAX]; + const char *iname = "/acpdump.din"; + const char *oname = "/acpdump.dsl"; const char *tmpdir; - char *tmpext; FILE *fp; size_t len; - int fd; + int fd, status; + pid_t pid; tmpdir = getenv("TMPDIR"); if (tmpdir == NULL) tmpdir = _PATH_TMP; - strncpy(tmpstr, tmpdir, sizeof(tmpstr)); - if (realpath(tmpstr, buf) == NULL) { + if (realpath(tmpdir, buf) == NULL) { perror("realpath tmp dir"); return; } - strncpy(tmpstr, buf, sizeof(tmpstr)); - strncat(tmpstr, "/acpidump.", sizeof(tmpstr) - strlen(buf)); - len = strlen(tmpstr); - tmpext = tmpstr + len; - strncpy(tmpext, "XXXXXX", sizeof(tmpstr) - len); - fd = mkstemp(tmpstr); + len = sizeof(wrkdir) - strlen(iname); + if ((size_t)snprintf(wrkdir, len, "%s/acpidump.XXXXXX", buf) > len-1 ) { + fprintf(stderr, "$TMPDIR too long\n"); + return; + } + if (mkdtemp(wrkdir) == NULL) { + perror("mkdtemp tmp working dir"); + return; + } + assert((size_t)snprintf(tmpstr, sizeof(tmpstr), "%s%s", wrkdir, iname) + <= sizeof(tmpstr) - 1); + fd = open(tmpstr, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR); if (fd < 0) { perror("iasl tmp file"); return; @@ -1494,28 +1501,46 @@ aml_disassemble(ACPI_TABLE_HEADER *rsdt, ACPI_TABLE_HEADER *dsdp) close(fd); /* Run iasl -d on the temp file */ - if (fork() == 0) { + if ((pid = fork()) == 0) { close(STDOUT_FILENO); if (vflag == 0) close(STDERR_FILENO); execl("/usr/sbin/iasl", "iasl", "-d", tmpstr, NULL); err(1, "exec"); } - - wait(NULL); - unlink(tmpstr); + if (pid > 0) + wait(&status); + if (unlink(tmpstr) < 0) { + perror("unlink"); + goto out; + } + if (pid < 0) { + perror("fork"); + goto out; + } + if (status != 0) { + fprintf(stderr, "iast exit status = %d\n", status); + } /* Dump iasl's output to stdout */ - strncpy(tmpext, "dsl", sizeof(tmpstr) - len); + assert((size_t)snprintf(tmpstr, sizeof(tmpstr), "%s%s", wrkdir, oname) + <= sizeof(tmpstr) -1); fp = fopen(tmpstr, "r"); - unlink(tmpstr); + if (unlink(tmpstr) < 0) { + perror("unlink"); + goto out; + } if (fp == NULL) { perror("iasl tmp file (read)"); - return; + goto out; } while ((len = fread(buf, 1, sizeof(buf), fp)) > 0) fwrite(buf, 1, len, stdout); fclose(fp); + + out: + if (rmdir(wrkdir) < 0) + perror("rmdir"); } void diff --git a/usr.sbin/bsnmpd/bsnmpd/Makefile b/usr.sbin/bsnmpd/bsnmpd/Makefile index 3e6df47..1724cea 100644 --- a/usr.sbin/bsnmpd/bsnmpd/Makefile +++ b/usr.sbin/bsnmpd/bsnmpd/Makefile @@ -16,7 +16,6 @@ XSYM= snmpMIB begemotSnmpdModuleTable begemotSnmpd begemotTrapSinkTable \ freeBSD freeBSDVersion CLEANFILES= oid.h tree.c tree.h MAN= bsnmpd.1 snmpmod.3 -NO_WERROR= FILESGROUPS= BMIBS DEFS @@ -27,7 +26,7 @@ DEFSDIR= ${SHAREDIR}/snmp/defs CFLAGS+= -DSNMPTREE_TYPES CFLAGS+= -I${CONTRIB}/lib -I${CONTRIB}/snmpd -I. -DUSE_LIBBEGEMOT -CFLAGS+= -DUSE_TCPWRAPPERS -DQUADFMT='"llu"' -DQUADXFMT='"llx"' +CFLAGS+= -DUSE_TCPWRAPPERS CFLAGS+= -DHAVE_STDINT_H -DHAVE_INTTYPES_H -DHAVE_ERR_H -DHAVE_STRLCPY DPADD= ${LIBBEGEMOT} ${LIBBSNMP} ${LIBWRAP} LDADD= -lbegemot -lbsnmp -lwrap @@ -49,4 +48,7 @@ MANFILTER= sed -e 's%@MODPATH@%${LIBDIR}/%g' \ -e 's%@DEFPATH@%${DEFSDIR}/%g' \ -e 's%@MIBSPATH@%${BMIBSDIR}/%g' +NO_WCAST_ALIGN= yes +WARNS?= 6 + .include <bsd.prog.mk> diff --git a/usr.sbin/bsnmpd/tools/bsnmptools/bsnmpget.c b/usr.sbin/bsnmpd/tools/bsnmptools/bsnmpget.c index fb0c7e5..28e2b58 100644 --- a/usr.sbin/bsnmpd/tools/bsnmptools/bsnmpget.c +++ b/usr.sbin/bsnmpd/tools/bsnmptools/bsnmpget.c @@ -500,7 +500,7 @@ snmptool_walk(struct snmp_toolinfo *snmptoolctx) outputs += rc; snmp_pdu_free(&resp); - if (rc < resp.nbindings) + if ((u_int)rc < resp.nbindings) break; snmpwalk_nextpdu_create(op, diff --git a/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmpmap.c b/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmpmap.c index 4f71c58..3833098 100644 --- a/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmpmap.c +++ b/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmpmap.c @@ -56,12 +56,11 @@ snmp_mapping_init(void) { struct snmp_mappings *m; - if ((m = malloc(sizeof(struct snmp_mappings))) == NULL) { + if ((m = calloc(1, sizeof(struct snmp_mappings))) == NULL) { syslog(LOG_ERR, "malloc() failed: %s", strerror(errno)); return (NULL); } - memset(m, 0, sizeof(struct snmp_mappings)); return (m); } @@ -269,21 +268,18 @@ enum_pair_insert(struct enum_pairs *headp, int32_t enum_val, char *enum_str) { struct enum_pair *e_new; - if ((e_new = malloc(sizeof(struct enum_pair))) == NULL) { + if ((e_new = calloc(1, sizeof(struct enum_pair))) == NULL) { syslog(LOG_ERR, "malloc() failed: %s", strerror(errno)); return (-1); } - memset(e_new, 0, sizeof(struct enum_pair)); - - if ((e_new->enum_str = malloc(strlen(enum_str) + 1)) == NULL) { + if ((e_new->enum_str = strdup(enum_str)) == NULL) { syslog(LOG_ERR, "malloc() failed: %s", strerror(errno)); free(e_new); return (-1); } e_new->enum_val = enum_val; - strlcpy(e_new->enum_str, enum_str, strlen(enum_str) + 1); STAILQ_INSERT_TAIL(headp, e_new, link); return (1); @@ -482,13 +478,11 @@ snmp_syntax_insert(struct snmp_idxlist *headp, struct enum_pairs *enums, { struct index *idx; - if ((idx = malloc(sizeof(struct index))) == NULL) { + if ((idx = calloc(1, sizeof(struct index))) == NULL) { syslog(LOG_ERR, "malloc() failed: %s", strerror(errno)); return (-1); } - memset(idx, 0, sizeof(struct index)); - if (snmp_index_insert(headp, idx) < 0) { free(idx); return (-1); @@ -558,18 +552,16 @@ snmp_enumtc_init(char *name) { struct enum_type *enum_tc; - if ((enum_tc = malloc(sizeof(struct enum_type))) == NULL) { + if ((enum_tc = calloc(1, sizeof(struct enum_type))) == NULL) { syslog(LOG_ERR, "malloc() failed: %s", strerror(errno)); return (NULL); } - memset(enum_tc, 0, sizeof(struct enum_type)); - if ((enum_tc->name = malloc(strlen(name) + 1)) == NULL) { + if ((enum_tc->name = strdup(name)) == NULL) { syslog(LOG_ERR, "malloc() failed: %s", strerror(errno)); free(enum_tc); return (NULL); } - strlcpy(enum_tc->name, name, strlen(name) + 1); return (enum_tc); } diff --git a/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptc.c b/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptc.c index 54644d6..6d83078 100644 --- a/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptc.c +++ b/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptc.c @@ -778,11 +778,11 @@ parse_ntp_ts(struct snmp_value *sv, char *val) saved_errno = errno; v = strtoul(val, &endptr, 10); if (errno != 0 || (v / 1000) > 9) { - saved_errno = errno; + errno = saved_errno; warnx("Integer value %s not supported", val); return (-1); } else - saved_errno = errno; + errno = saved_errno; if (*endptr != '.') { warnx("Failed reading octet - %s", val); @@ -799,11 +799,11 @@ parse_ntp_ts(struct snmp_value *sv, char *val) saved_errno = errno; v = strtoul(val, &endptr, 10); if (errno != 0 || (v / 1000) > 9) { - saved_errno = errno; + errno = saved_errno; warnx("Integer value %s not supported", val); return (-1); } else - saved_errno = errno; + errno = saved_errno; for (i = 0, d = 1000; i < 4; i++) { ntp_ts[i + 4] = v / d; diff --git a/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c b/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c index 1f59f71..959de71 100644 --- a/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c +++ b/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c @@ -251,7 +251,7 @@ add_filename(struct snmp_toolinfo *snmptoolctx, const char *filename, return (0); } - if ((fstring = malloc(strlen(filename) + 1)) == NULL) { + if ((fstring = strdup(filename)) == NULL) { warnx("malloc() failed - %s", strerror(errno)); return (-1); } @@ -264,7 +264,6 @@ add_filename(struct snmp_toolinfo *snmptoolctx, const char *filename, if (cut != NULL) asn_append_oid(&(entry->cut), cut); - strlcpy(fstring, filename, strlen(filename) + 1); entry->name = fstring; entry->done = done; SLIST_INSERT_HEAD(&snmptoolctx->filelist, entry, link); @@ -1060,7 +1059,7 @@ snmp_oid2asn_oid(struct snmp_toolinfo *snmptoolctx, char *str, struct asn_oid *oid) { int32_t i; - char string[MAXSTR], *endptr; + char string[MAXSTR + 1], *endptr; struct snmp_object obj; for (i = 0; i < MAXSTR; i++) @@ -1076,7 +1075,6 @@ snmp_oid2asn_oid(struct snmp_toolinfo *snmptoolctx, char *str, return (NULL); } else { strlcpy(string, str, i + 1); - string[i] = '\0'; if (snmp_lookup_enumoid(snmptoolctx, &obj, string) < 0) { warnx("Unknown string - %s", string); return (NULL); diff --git a/usr.sbin/camdd/camdd.c b/usr.sbin/camdd/camdd.c index 9284eb5..095affd 100644 --- a/usr.sbin/camdd/camdd.c +++ b/usr.sbin/camdd/camdd.c @@ -1079,9 +1079,7 @@ camdd_probe_file(int fd, struct camdd_io_opts *io_opts, int retry_count, retval = fstat(fd, &file_dev->sb); if (retval != 0) { warn("Cannot stat %s", dev->device_name); - goto bailout; - camdd_free_dev(dev); - dev = NULL; + goto bailout_error; } if (S_ISREG(file_dev->sb.st_mode)) { file_dev->file_type = CAMDD_FILE_REG; @@ -1383,6 +1381,11 @@ camdd_probe_pass(struct cam_device *cam_dev, struct camdd_io_opts *io_opts, block_len = scsi_4btoul(rcaplong.length); rcap_done: + if (block_len == 0) { + warnx("Sector size for %s%u is 0, cannot continue", + cam_dev->device_name, cam_dev->dev_unit_num); + goto bailout_error; + } bzero(&(&ccb->ccb_h)[1], sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr)); diff --git a/usr.sbin/extattr/Makefile b/usr.sbin/extattr/Makefile index 8e2b5f7..9f5721d 100644 --- a/usr.sbin/extattr/Makefile +++ b/usr.sbin/extattr/Makefile @@ -1,8 +1,12 @@ # $FreeBSD$ +.include <bsd.own.mk> + PROG= rmextattr MAN= rmextattr.8 +LDADD= -lsbuf + LINKS+= ${BINDIR}/rmextattr ${BINDIR}/getextattr LINKS+= ${BINDIR}/rmextattr ${BINDIR}/setextattr LINKS+= ${BINDIR}/rmextattr ${BINDIR}/lsextattr @@ -11,4 +15,8 @@ MLINKS+= rmextattr.8 setextattr.8 MLINKS+= rmextattr.8 getextattr.8 MLINKS+= rmextattr.8 lsextattr.8 +.if ${MK_TESTS} != "no" +SUBDIR+= tests +.endif + .include <bsd.prog.mk> diff --git a/usr.sbin/extattr/rmextattr.8 b/usr.sbin/extattr/rmextattr.8 index c51fa6d..3b0988f 100644 --- a/usr.sbin/extattr/rmextattr.8 +++ b/usr.sbin/extattr/rmextattr.8 @@ -31,7 +31,7 @@ .\" .\" $FreeBSD$ .\" -.Dd August 30, 2000 +.Dd April 27, 2016 .Dt RMEXTATTR 8 .Os .Sh NAME @@ -61,6 +61,12 @@ .Ar attrname .Ar attrvalue .Ar filename ... +.Nm setextattr +.Fl i +.Op Fl fhnq +.Ar attrnamespace +.Ar attrname +.Ar filename ... .Sh DESCRIPTION These utilities @@ -91,6 +97,9 @@ the remaining arguments. (No follow.) If the file is a symbolic link, perform the operation on the link itself rather than the file that the link points to. +.It Fl i +(From stdin.) +Read attribute data from stdin instead of as an argument. .It Fl n .Dv ( NUL Ns -terminate.) @@ -99,6 +108,7 @@ link itself rather than the file that the link points to. .It Fl q (Quiet.) Do not print out the pathname and suppress error messages. +When given twice, print only the attribute value, with no trailing newline. .It Fl s (Stringify.) Escape nonprinting characters and put quotes around the output. @@ -109,7 +119,9 @@ Print the output in hexadecimal. .Sh EXAMPLES .Bd -literal setextattr system md5 `md5 -q /boot/kernel/kernel` /boot/kernel/kernel +md5 -q /boot/kernel/kernel | setextattr -i system md5 /boot/kernel/kernel getextattr system md5 /boot/kernel/kernel +getextattr -qq system md5 /boot/kernel/kernel | od -x lsextattr system /boot/kernel/kernel rmextattr system md5 /boot/kernel/kernel .Ed @@ -129,7 +141,3 @@ to be associated with each file or directory. .Sh AUTHORS .An Robert N M Watson .An Poul-Henning Kamp -.Sh BUGS -The -.Nm setextattr -utility can only be used to set attributes to strings. diff --git a/usr.sbin/extattr/rmextattr.c b/usr.sbin/extattr/rmextattr.c index c061943..4373fd6 100644 --- a/usr.sbin/extattr/rmextattr.c +++ b/usr.sbin/extattr/rmextattr.c @@ -37,6 +37,7 @@ */ #include <sys/types.h> +#include <sys/sbuf.h> #include <sys/uio.h> #include <sys/extattr.h> @@ -64,6 +65,8 @@ usage(void) case EASET: fprintf(stderr, "usage: setextattr [-fhnq] attrnamespace"); fprintf(stderr, " attrname attrvalue filename ...\n"); + fprintf(stderr, " or setextattr -i [-fhnq] attrnamespace"); + fprintf(stderr, " attrname filename ...\n"); exit(-1); case EARM: fprintf(stderr, "usage: rmextattr [-fhq] attrnamespace"); @@ -99,24 +102,28 @@ mkbuf(char **buf, int *oldlen, int newlen) int main(int argc, char *argv[]) { - char *buf, *visbuf, *p; +#define STDIN_BUF_SZ 1024 + char stdin_data[STDIN_BUF_SZ]; + char *p; const char *options, *attrname; size_t len; ssize_t ret; - int buflen, visbuflen, ch, error, i, arg_counter, attrnamespace, - minargc; + int ch, error, i, arg_counter, attrnamespace, minargc; + char *visbuf = NULL; + int visbuflen = 0; + char *buf = NULL; + int buflen = 0; + struct sbuf *attrvalue = NULL; int flag_force = 0; int flag_nofollow = 0; int flag_null = 0; - int flag_quiet = 0; + int count_quiet = 0; + int flag_from_stdin = 0; int flag_string = 0; int flag_hex = 0; - visbuflen = buflen = 0; - visbuf = buf = NULL; - p = basename(argv[0]); if (p == NULL) p = argv[0]; @@ -126,8 +133,8 @@ main(int argc, char *argv[]) minargc = 3; } else if (!strcmp(p, "setextattr")) { what = EASET; - options = "fhnq"; - minargc = 4; + options = "fhinq"; + minargc = 3; } else if (!strcmp(p, "rmextattr")) { what = EARM; options = "fhq"; @@ -148,11 +155,14 @@ main(int argc, char *argv[]) case 'h': flag_nofollow = 1; break; + case 'i': + flag_from_stdin = 1; + break; case 'n': flag_null = 1; break; case 'q': - flag_quiet = 1; + count_quiet += 1; break; case 's': flag_string = 1; @@ -169,6 +179,9 @@ main(int argc, char *argv[]) argc -= optind; argv += optind; + if (what == EASET && flag_from_stdin == 0) + minargc++; + if (argc < minargc) usage(); @@ -184,9 +197,15 @@ main(int argc, char *argv[]) attrname = NULL; if (what == EASET) { - mkbuf(&buf, &buflen, strlen(argv[0]) + 1); - strcpy(buf, argv[0]); - argc--; argv++; + attrvalue = sbuf_new_auto(); + if (flag_from_stdin) { + while ((error = read(0, stdin_data, STDIN_BUF_SZ)) > 0) + sbuf_bcat(attrvalue, stdin_data, error); + } else { + sbuf_cpy(attrvalue, argv[0]); + argc--; argv++; + } + sbuf_finish(attrvalue); } for (arg_counter = 0; arg_counter < argc; arg_counter++) { @@ -202,15 +221,17 @@ main(int argc, char *argv[]) continue; break; case EASET: - len = strlen(buf) + flag_null; + len = sbuf_len(attrvalue) + flag_null; if (flag_nofollow) ret = extattr_set_link(argv[arg_counter], - attrnamespace, attrname, buf, len); + attrnamespace, attrname, + sbuf_data(attrvalue), len); else ret = extattr_set_file(argv[arg_counter], - attrnamespace, attrname, buf, len); + attrnamespace, attrname, + sbuf_data(attrvalue), len); if (ret >= 0) { - if ((size_t)ret != len && !flag_quiet) { + if ((size_t)ret != len && !count_quiet) { warnx("Set %zd bytes of %zu for %s", ret, len, attrname); } @@ -235,7 +256,7 @@ main(int argc, char *argv[]) attrnamespace, buf, buflen); if (ret < 0) break; - if (!flag_quiet) + if (!count_quiet) printf("%s\t", argv[arg_counter]); for (i = 0; i < ret; i += ch + 1) { /* The attribute name length is unsigned. */ @@ -243,7 +264,7 @@ main(int argc, char *argv[]) printf("%s%*.*s", i ? "\t" : "", ch, ch, buf + i + 1); } - if (!flag_quiet || ret > 0) + if (!count_quiet || ret > 0) printf("\n"); continue; case EAGET: @@ -264,29 +285,27 @@ main(int argc, char *argv[]) attrnamespace, attrname, buf, buflen); if (ret < 0) break; - if (!flag_quiet) + if (!count_quiet) printf("%s\t", argv[arg_counter]); if (flag_string) { mkbuf(&visbuf, &visbuflen, ret * 4 + 1); strvisx(visbuf, buf, ret, VIS_SAFE | VIS_WHITE); - printf("\"%s\"\n", visbuf); - continue; + printf("\"%s\"", visbuf); } else if (flag_hex) { for (i = 0; i < ret; i++) printf("%s%02x", i ? " " : "", - buf[i]); - printf("\n"); - continue; + (unsigned char)buf[i]); } else { fwrite(buf, ret, 1, stdout); - printf("\n"); - continue; } + if (count_quiet < 2) + printf("\n"); + continue; default: break; } - if (!flag_quiet) + if (!count_quiet) warn("%s: failed", argv[arg_counter]); if (flag_force) continue; diff --git a/usr.sbin/extattr/tests/Makefile b/usr.sbin/extattr/tests/Makefile new file mode 100644 index 0000000..ca8200e --- /dev/null +++ b/usr.sbin/extattr/tests/Makefile @@ -0,0 +1,7 @@ +# $FreeBSD$ + +TESTSDIR= ${TESTSBASE}/usr.sbin/extattr + +ATF_TESTS_SH= extattr_test + +.include <bsd.test.mk> diff --git a/usr.sbin/extattr/tests/extattr_test.sh b/usr.sbin/extattr/tests/extattr_test.sh new file mode 100755 index 0000000..d9c0c71 --- /dev/null +++ b/usr.sbin/extattr/tests/extattr_test.sh @@ -0,0 +1,335 @@ +# +# Copyright (c) 2016 Spectra Logic Corp +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ + +atf_test_case bad_namespace +bad_namespace_head() { + atf_set "descr" "Can't set attributes for nonexistent namespaces" +} +bad_namespace_body() { + touch foo + atf_check -s not-exit:0 -e match:"Invalid argument" \ + setextattr badnamespace myattr X foo + atf_check -s not-exit:0 -e match:"Invalid argument" \ + lsextattr -q badnamespace foo +} + +atf_test_case hex +hex_head() { + atf_set "descr" "Set and get attribute values in hexadecimal" +} +hex_body() { + touch foo + atf_check -s exit:0 -o empty setextattr user myattr XYZ foo + atf_check -s exit:0 -o inline:"58 59 5a\n" \ + getextattr -qx user myattr foo +} + +atf_test_case hex_nonascii +hex_nonascii_head() { + atf_set "descr" "Get binary attribute values in hexadecimal" +} +hex_nonascii_body() { + touch foo + BINSTUFF=`echo $'\x20\x30\x40\x55\x66\x70\x81\xa2\xb3\xee\xff'` + atf_check -s exit:0 -o empty setextattr user myattr "$BINSTUFF" foo + getextattr user myattr foo + atf_check -s exit:0 -o inline:"20 30 40 55 66 70 81 a2 b3 ee ff\n" \ + getextattr -qx user myattr foo +} + +atf_test_case long_name +long_name_head() { + atf_set "descr" "A maximum length attribute name" +} +long_name_body() { + # https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=208965 + atf_expect_fail "BUG 208965 extattr(2) doesn't allow maxlen attr names" + + ATTRNAME=`jot -b X -s "" 255 0` + touch foo + atf_check -s exit:0 -o empty setextattr user $ATTRNAME myvalue foo + atf_check -s exit:0 -o inline:"${ATTRNAME}\n" lsextattr -q user foo + atf_check -s exit:0 -o inline:"myvalue\n" \ + getextattr -q user ${ATTRNAME} foo + atf_check -s exit:0 -o empty rmextattr user ${ATTRNAME} foo + atf_check -s exit:0 -o empty lsextattr -q user foo +} + +atf_test_case loud +loud_head() { + atf_set "descr" "Loud (non -q) output for each command" +} +loud_body() { + touch foo + # setextattr(8) and friends print hard tabs. Use printf to convert + # them to spaces before checking the output. + atf_check -s exit:0 -o empty setextattr user myattr myvalue foo + atf_check -s exit:0 -o inline:"foo myattr" \ + printf "%s %s" $(lsextattr user foo) + atf_check -s exit:0 -o inline:"foo myvalue" \ + printf "%s %s" $(getextattr user myattr foo) + atf_check -s exit:0 -o empty rmextattr user myattr foo + atf_check -s exit:0 -o inline:"foo" printf %s $(lsextattr user foo) +} + +atf_test_case noattrs +noattrs_head() { + atf_set "descr" "A file with no extended attributes" +} +noattrs_body() { + touch foo + atf_check -s exit:0 -o empty lsextattr -q user foo +} + +atf_test_case nonexistent_file +nonexistent_file_head() { + atf_set "descr" "A file that does not exist" +} +nonexistent_file_body() { + atf_check -s exit:1 -e match:"No such file or directory" \ + lsextattr user foo + atf_check -s exit:1 -e match:"No such file or directory" \ + setextattr user myattr myvalue foo + atf_check -s exit:1 -e match:"No such file or directory" \ + getextattr user myattr foo + atf_check -s exit:1 -e match:"No such file or directory" \ + rmextattr user myattr foo +} + +atf_test_case null +null_head() { + atf_set "descr" "NUL-terminate an attribute value" +} +null_body() { + touch foo + atf_check -s exit:0 -o empty setextattr -n user myattr myvalue foo + atf_check -s exit:0 -o inline:"myvalue\0\n" getextattr -q user myattr foo +} + +atf_test_case one_user_attr +one_user_attr_head() { + atf_set "descr" "A file with one extended attribute" +} +one_user_attr_body() { + touch foo + atf_check -s exit:0 -o empty setextattr user myattr myvalue foo + atf_check -s exit:0 -o inline:"myattr\n" lsextattr -q user foo + atf_check -s exit:0 -o inline:"myvalue\n" getextattr -q user myattr foo + atf_check -s exit:0 -o empty rmextattr user myattr foo + atf_check -s exit:0 -o empty lsextattr -q user foo +} + +atf_test_case one_system_attr +one_system_attr_head() { + atf_set "descr" "A file with one extended attribute" + atf_set "require.user" "root" +} +one_system_attr_body() { + touch foo + atf_check -s exit:0 -o empty setextattr system myattr myvalue foo + atf_check -s exit:0 -o inline:"myattr\n" lsextattr -q system foo + atf_check -s exit:0 -o inline:"myvalue\n" getextattr -q system myattr foo + atf_check -s exit:0 -o empty rmextattr system myattr foo + atf_check -s exit:0 -o empty lsextattr -q system foo +} + +atf_test_case stdin +stdin_head() { + atf_set "descr" "Set attribute value from stdin" +} +stdin_body() { + dd if=/dev/random of=infile bs=1k count=8 + touch foo + setextattr -i user myattr foo < infile || atf_fail "setextattr failed" + atf_check -s exit:0 -o inline:"myattr\n" lsextattr -q user foo + getextattr -qq user myattr foo > outfile || atf_fail "getextattr failed" + atf_check -s exit:0 cmp -s infile outfile +} + +atf_test_case stringify +stringify_head() { + atf_set "descr" "Stringify the output of getextattr" +} +stringify_body() { + touch foo + atf_check -s exit:0 -o empty setextattr user myattr "my value" foo + atf_check -s exit:0 -o inline:"\"my\\\040value\"\n" \ + getextattr -qs user myattr foo +} + +atf_test_case symlink +symlink_head() { + atf_set "descr" "A symlink to an ordinary file" +} +symlink_body() { + touch foo + ln -s foo foolink + atf_check -s exit:0 -o empty setextattr user myattr myvalue foolink + atf_check -s exit:0 -o inline:"myvalue\n" \ + getextattr -q user myattr foolink + atf_check -s exit:0 -o inline:"myvalue\n" getextattr -q user myattr foo +} + +atf_test_case symlink_nofollow +symlink_nofollow_head() { + atf_set "descr" "Operating directly on a symlink" +} +symlink_nofollow_body() { + touch foo + ln -s foo foolink + # Check that with -h we can operate directly on the link + atf_check -s exit:0 -o empty setextattr -h user myattr myvalue foolink + atf_check -s exit:0 -o inline:"myvalue\n" \ + getextattr -qh user myattr foolink + atf_check -s exit:1 -e match:"Attribute not found" \ + getextattr user myattr foolink + atf_check -s exit:1 -e match:"Attribute not found" \ + getextattr user myattr foo + + # Check that with -h we cannot operate on the destination file + atf_check -s exit:0 -o empty setextattr user otherattr othervalue foo + atf_check -s exit:1 getextattr -qh user otherattr foolink +} + +atf_test_case system_and_user_attrs +system_and_user_attrs_head() { + atf_set "descr" "A file with both system and user extended attributes" + atf_set "require.user" "root" +} +system_and_user_attrs_body() { + touch foo + atf_check -s exit:0 -o empty setextattr user userattr userval foo + atf_check -s exit:0 -o empty setextattr system sysattr sysval foo + atf_check -s exit:0 -o inline:"userattr\n" lsextattr -q user foo + atf_check -s exit:0 -o inline:"sysattr\n" lsextattr -q system foo + + atf_check -s exit:0 -o inline:"userval\n" getextattr -q user userattr foo + atf_check -s exit:0 -o inline:"sysval\n" getextattr -q system sysattr foo + atf_check -s exit:0 -o empty rmextattr user userattr foo + atf_check -s exit:0 -o empty rmextattr system sysattr foo + atf_check -s exit:0 -o empty lsextattr -q user foo + atf_check -s exit:0 -o empty lsextattr -q system foo +} + +atf_test_case two_files +two_files_head() { + atf_set "descr" "Manipulate two files" +} +two_files_body() { + touch foo bar + atf_check -s exit:0 -o empty setextattr user myattr myvalue foo bar + atf_check -s exit:0 -o inline:"foo\tmyattr\nbar\tmyattr\n" \ + lsextattr user foo bar + atf_check -s exit:0 \ + -o inline:"foo\tmyvalue\nbar\tmyvalue\n" \ + getextattr user myattr foo bar + atf_check -s exit:0 -o empty rmextattr user myattr foo bar + atf_check -s exit:0 -o empty lsextattr -q user foo bar +} + +atf_test_case two_files_force +two_files_force_head() { + atf_set "descr" "Manipulate two files. The first does not exist" +} +two_files_force_body() { + touch bar + atf_check -s exit:1 -e match:"No such file or directory" \ + setextattr user myattr myvalue foo bar + atf_check -s exit:0 -e ignore setextattr -f user myattr myvalue foo bar + atf_check -s exit:1 -e match:"No such file or directory" \ + lsextattr user foo bar + atf_check -s exit:0 -e ignore -o inline:"bar\tmyattr\n" \ + lsextattr -f user foo bar + atf_check -s exit:1 -e match:"No such file or directory" \ + getextattr user myattr foo bar + atf_check -s exit:0 -e ignore \ + -o inline:"bar\tmyvalue\n" \ + getextattr -f user myattr foo bar + atf_check -s exit:1 -e match:"No such file or directory" \ + rmextattr user myattr foo bar + atf_check -s exit:0 -e ignore \ + rmextattr -f user myattr foo bar + atf_check -s exit:0 -o empty lsextattr -q user bar +} + +atf_test_case two_user_attrs +two_user_attrs_head() { + atf_set "descr" "A file with two extended attributes" +} +two_user_attrs_body() { + touch foo + atf_check -s exit:0 -o empty setextattr user myattr1 myvalue1 foo + atf_check -s exit:0 -o empty setextattr user myattr2 myvalue2 foo + # lsextattr could return the attributes in any order, so we must be + # careful how we compare them. + raw_output=`lsextattr -q user foo` || atf_fail "lsextattr failed" + tabless_output=`printf "%s %s" ${raw_output}` + if [ "myattr1 myattr2" != "${tabless_output}" -a \ + "myattr2 myattr1" != "${tabless_output}" ]; then + atf_fail "lsextattr printed ${tabless_output}" + fi + atf_check -s exit:0 -o inline:"myvalue1\n" getextattr -q user myattr1 foo + atf_check -s exit:0 -o inline:"myvalue2\n" getextattr -q user myattr2 foo + atf_check -s exit:0 -o empty rmextattr user myattr2 foo + atf_check -s exit:0 -o empty rmextattr user myattr1 foo + atf_check -s exit:0 -o empty lsextattr -q user foo +} + +atf_test_case unprivileged_user_cannot_set_system_attr +unprivileged_user_cannot_set_system_attr_head() { + atf_set "descr" "Unprivileged users can't set system attributes" + atf_set "require.user" "unprivileged" +} +unprivileged_user_cannot_set_system_attr_body() { + touch foo + atf_check -s exit:1 -e match:"Operation not permitted" \ + setextattr system myattr myvalue foo +} + + +atf_init_test_cases() { + atf_add_test_case bad_namespace + atf_add_test_case hex + atf_add_test_case hex_nonascii + atf_add_test_case long_name + atf_add_test_case loud + atf_add_test_case noattrs + atf_add_test_case nonexistent_file + atf_add_test_case null + atf_add_test_case symlink_nofollow + atf_add_test_case one_user_attr + atf_add_test_case one_system_attr + atf_add_test_case stdin + atf_add_test_case stringify + atf_add_test_case symlink + atf_add_test_case symlink_nofollow + atf_add_test_case system_and_user_attrs + atf_add_test_case two_files + atf_add_test_case two_files_force + atf_add_test_case two_user_attrs + atf_add_test_case unprivileged_user_cannot_set_system_attr +} diff --git a/usr.sbin/ntp/config.h b/usr.sbin/ntp/config.h index 30988ea..d11819c 100644 --- a/usr.sbin/ntp/config.h +++ b/usr.sbin/ntp/config.h @@ -1449,7 +1449,7 @@ #define PACKAGE_NAME "ntp" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "ntp 4.2.8p7" +#define PACKAGE_STRING "ntp 4.2.8p8" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "ntp" @@ -1458,7 +1458,7 @@ #define PACKAGE_URL "http://www.ntp.org./" /* Define to the version of this package. */ -#define PACKAGE_VERSION "4.2.8p7" +#define PACKAGE_VERSION "4.2.8p8" /* data dir */ #define PERLLIBDIR "/usr/local/share/ntp/lib" @@ -1639,7 +1639,7 @@ typedef unsigned int uintptr_t; /* #undef USE_UDP_SIGPOLL */ /* Version number of package */ -#define VERSION "4.2.8p7" +#define VERSION "4.2.8p8" /* vsnprintf expands "%m" to strerror(errno) */ /* #undef VSNPRINTF_PERCENT_M */ @@ -1816,5 +1816,5 @@ typedef union mpinfou { /* * FreeBSD specific: Explicitly specify date/time for reproducible build. */ -#define MKREPRO_DATE "Apr 27 2016" -#define MKREPRO_TIME "05:53:49" +#define MKREPRO_DATE "Jun 03 2016" +#define MKREPRO_TIME "06:34:37" diff --git a/usr.sbin/ntp/doc/ntp-keygen.8 b/usr.sbin/ntp/doc/ntp-keygen.8 index 4b58a4c..bb7972a 100644 --- a/usr.sbin/ntp/doc/ntp-keygen.8 +++ b/usr.sbin/ntp/doc/ntp-keygen.8 @@ -1,11 +1,11 @@ -.Dd April 26 2016 +.Dd June 2 2016 .Dt NTP_KEYGEN 8 User Commands .Os .\" EDIT THIS FILE WITH CAUTION (ntp-keygen-opts.mdoc) .\" .\" $FreeBSD$ .\" -.\" It has been AutoGen-ed April 26, 2016 at 08:30:23 PM by AutoGen 5.18.5 +.\" It has been AutoGen-ed June 2, 2016 at 07:39:43 AM by AutoGen 5.18.5 .\" From the definitions ntp-keygen-opts.def .\" and the template file agmdoc-cmd.tpl .Sh NAME diff --git a/usr.sbin/ntp/doc/ntp.conf.5 b/usr.sbin/ntp/doc/ntp.conf.5 index 4e45240..42af4a5 100644 --- a/usr.sbin/ntp/doc/ntp.conf.5 +++ b/usr.sbin/ntp/doc/ntp.conf.5 @@ -1,11 +1,11 @@ -.Dd April 26 2016 +.Dd June 2 2016 .Dt NTP_CONF 5 File Formats .Os .\" EDIT THIS FILE WITH CAUTION (ntp.mdoc) .\" .\" $FreeBSD$ .\" -.\" It has been AutoGen-ed April 26, 2016 at 08:28:36 PM by AutoGen 5.18.5 +.\" It has been AutoGen-ed June 2, 2016 at 07:36:16 AM by AutoGen 5.18.5 .\" From the definitions ntp.conf.def .\" and the template file agmdoc-cmd.tpl .Sh NAME @@ -2442,6 +2442,7 @@ The default value is 46, signifying Expedited Forwarding. .Cm calibrate | Cm kernel | .Cm mode7 | Cm monitor | .Cm ntp | Cm stats | +.Cm peer_clear_digest_early | .Cm unpeer_crypto_early | Cm unpeer_crypto_nak_early | Cm unpeer_digest_early .Oc .Xc @@ -2451,6 +2452,7 @@ The default value is 46, signifying Expedited Forwarding. .Cm calibrate | Cm kernel | .Cm mode7 | Cm monitor | .Cm ntp | Cm stats | +.Cm peer_clear_digest_early | .Cm unpeer_crypto_early | Cm unpeer_crypto_nak_early | Cm unpeer_digest_early .Oc .Xc @@ -2518,6 +2520,26 @@ closes the feedback loop, which is useful for testing. The default for this flag is .Ic enable . +.It Cm peer_clear_digest_early +By default, if +.Xr ntpd 8 +is using autokey and it +receives a crypto\-NAK packet that +passes the duplicate packet and origin timestamp checks +the peer variables are immediately cleared. +While this is generally a feature +as it allows for quick recovery if a server key has changed, +a properly forged and appropriately delivered crypto\-NAK packet +can be used in a DoS attack. +If you have active noticable problems with this type of DoS attack +then you should consider +disabling this option. +You can check your +.Cm peerstats +file for evidence of any of these attacks. +The +default for this flag is +.Ic enable . .It Cm stats Enables the statistics facility. See the diff --git a/usr.sbin/ntp/doc/ntp.keys.5 b/usr.sbin/ntp/doc/ntp.keys.5 index 6fb04bf..06cf644 100644 --- a/usr.sbin/ntp/doc/ntp.keys.5 +++ b/usr.sbin/ntp/doc/ntp.keys.5 @@ -1,11 +1,11 @@ -.Dd April 26 2016 +.Dd June 2 2016 .Dt NTP_KEYS 5 File Formats .Os SunOS 5.10 .\" EDIT THIS FILE WITH CAUTION (ntp.mdoc) .\" .\" $FreeBSD$ .\" -.\" It has been AutoGen-ed April 26, 2016 at 08:28:39 PM by AutoGen 5.18.5 +.\" It has been AutoGen-ed June 2, 2016 at 07:36:20 AM by AutoGen 5.18.5 .\" From the definitions ntp.keys.def .\" and the template file agmdoc-file.tpl .Sh NAME diff --git a/usr.sbin/ntp/doc/ntpd.8 b/usr.sbin/ntp/doc/ntpd.8 index d7e6650..bb51eb3 100644 --- a/usr.sbin/ntp/doc/ntpd.8 +++ b/usr.sbin/ntp/doc/ntpd.8 @@ -1,11 +1,11 @@ -.Dd April 26 2016 +.Dd June 2 2016 .Dt NTPD 8 User Commands .Os .\" EDIT THIS FILE WITH CAUTION (ntpd-opts.mdoc) .\" .\" $FreeBSD$ .\" -.\" It has been AutoGen-ed April 26, 2016 at 08:28:41 PM by AutoGen 5.18.5 +.\" It has been AutoGen-ed June 2, 2016 at 07:36:22 AM by AutoGen 5.18.5 .\" From the definitions ntpd-opts.def .\" and the template file agmdoc-cmd.tpl .Sh NAME diff --git a/usr.sbin/ntp/doc/ntpdc.8 b/usr.sbin/ntp/doc/ntpdc.8 index 7b73651..39de44d 100644 --- a/usr.sbin/ntp/doc/ntpdc.8 +++ b/usr.sbin/ntp/doc/ntpdc.8 @@ -1,11 +1,11 @@ -.Dd April 26 2016 +.Dd June 2 2016 .Dt NTPDC 8 User Commands .Os .\" EDIT THIS FILE WITH CAUTION (ntpdc-opts.mdoc) .\" .\" $FreeBSD$ .\" -.\" It has been AutoGen-ed April 26, 2016 at 08:29:08 PM by AutoGen 5.18.5 +.\" It has been AutoGen-ed June 2, 2016 at 07:36:58 AM by AutoGen 5.18.5 .\" From the definitions ntpdc-opts.def .\" and the template file agmdoc-cmd.tpl .Sh NAME diff --git a/usr.sbin/ntp/doc/ntpq.8 b/usr.sbin/ntp/doc/ntpq.8 index 6f2d080..60e66de 100644 --- a/usr.sbin/ntp/doc/ntpq.8 +++ b/usr.sbin/ntp/doc/ntpq.8 @@ -1,11 +1,11 @@ -.Dd April 26 2016 +.Dd June 2 2016 .Dt NTPQ 8 User Commands .Os .\" EDIT THIS FILE WITH CAUTION (ntpq-opts.mdoc) .\" .\" $FreeBSD$ .\" -.\" It has been AutoGen-ed April 26, 2016 at 08:29:41 PM by AutoGen 5.18.5 +.\" It has been AutoGen-ed June 2, 2016 at 07:37:48 AM by AutoGen 5.18.5 .\" From the definitions ntpq-opts.def .\" and the template file agmdoc-cmd.tpl .Sh NAME diff --git a/usr.sbin/ntp/doc/sntp.8 b/usr.sbin/ntp/doc/sntp.8 index a0172a3..c0ab263 100644 --- a/usr.sbin/ntp/doc/sntp.8 +++ b/usr.sbin/ntp/doc/sntp.8 @@ -1,11 +1,11 @@ -.Dd April 26 2016 +.Dd June 2 2016 .Dt SNTP 8 User Commands .Os .\" EDIT THIS FILE WITH CAUTION (sntp-opts.mdoc) .\" .\" $FreeBSD$ .\" -.\" It has been AutoGen-ed April 26, 2016 at 08:21:15 PM by AutoGen 5.18.5 +.\" It has been AutoGen-ed June 2, 2016 at 07:20:03 AM by AutoGen 5.18.5 .\" From the definitions sntp-opts.def .\" and the template file agmdoc-cmd.tpl .Sh NAME diff --git a/usr.sbin/ntp/scripts/mkver b/usr.sbin/ntp/scripts/mkver index 373bb5f..5318024 100755 --- a/usr.sbin/ntp/scripts/mkver +++ b/usr.sbin/ntp/scripts/mkver @@ -6,7 +6,7 @@ PROG=${1-UNKNOWN} ConfStr="$PROG" -ConfStr="$ConfStr 4.2.8p7" +ConfStr="$ConfStr 4.2.8p8" case "$CSET" in '') ;; diff --git a/usr.sbin/tzsetup/tzsetup.c b/usr.sbin/tzsetup/tzsetup.c index cea8533..5299ce6 100644 --- a/usr.sbin/tzsetup/tzsetup.c +++ b/usr.sbin/tzsetup/tzsetup.c @@ -837,7 +837,9 @@ install_zoneinfo(const char *zoneinfo) FILE *f; char path_zoneinfo_file[MAXPATHLEN]; - sprintf(path_zoneinfo_file, "%s/%s", path_zoneinfo, zoneinfo); + if ((size_t)snprintf(path_zoneinfo_file, sizeof(path_zoneinfo_file), + "%s/%s", path_zoneinfo, zoneinfo) >= sizeof(path_zoneinfo_file)) + errx(1, "%s/%s name too long", path_zoneinfo, zoneinfo); rv = install_zoneinfo_file(path_zoneinfo_file); /* Save knowledge for later */ diff --git a/usr.sbin/ypserv/yp_dnslookup.c b/usr.sbin/ypserv/yp_dnslookup.c index dfb5594..947df59 100644 --- a/usr.sbin/ypserv/yp_dnslookup.c +++ b/usr.sbin/ypserv/yp_dnslookup.c @@ -489,9 +489,6 @@ yp_async_lookup_addr(struct svc_req *rqstp, char *addr, int af) yp_find_dnsqent(svcudp_get_xid(rqstp->rq_xprt),BY_RPC_XID) != NULL) return(YP_TRUE); - if ((q = yp_malloc_dnsent()) == NULL) - return(YP_YPERR); - switch (af) { case AF_INET: if (inet_aton(addr, (struct in_addr *)uaddr) != 1) @@ -516,6 +513,9 @@ yp_async_lookup_addr(struct svc_req *rqstp, char *addr, int af) return(YP_YPERR); } + if ((q = yp_malloc_dnsent()) == NULL) + return(YP_YPERR); + if (debug) yp_error("DNS address is: %s", buf); diff --git a/usr.sbin/ypserv/yp_server.c b/usr.sbin/ypserv/yp_server.c index ba20c3cd..304fd50 100644 --- a/usr.sbin/ypserv/yp_server.c +++ b/usr.sbin/ypserv/yp_server.c @@ -711,6 +711,7 @@ yp_maplist_create(const char *domain) yp_error("strdup() failed: %s",strerror(errno)); closedir(dird); yp_maplist_free(yp_maplist); + free(cur); return(NULL); } cur->next = yp_maplist; |