Permalink
Browse files

AMD64 - AUDIT RUN - Fix format strings, size_t, and other issues

  • Loading branch information...
Matthew Dillon
Matthew Dillon committed Aug 21, 2009
1 parent 4ae574e commit a276dc6b198ac253911f4d7e2994422e81efea72
Showing with 439 additions and 337 deletions.
  1. +7 −5 bin/dd/args.c
  2. +11 −8 bin/dd/misc.c
  3. +1 −1 bin/sh/mksyntax.c
  4. +1 −0 bin/sh/parser.c
  5. +4 −1 contrib/com_err/getarg.c
  6. +1 −5 contrib/libevent/kqueue.c
  7. +1 −1 contrib/ncurses-5.4/ncurses/trace/lib_tracechr.c
  8. +1 −0 contrib/opie/libopie/generator.c
  9. +1 −0 contrib/opie/libopie/lookup.c
  10. +1 −0 contrib/opie/libopie/newseed.c
  11. +1 −0 contrib/opie/libopie/passwd.c
  12. +2 −0 contrib/opie/libopie/randomchallenge.c
  13. +2 −0 contrib/opie/libopie/version.c
  14. +1 −1 contrib/sendmail-8.14/libmilter/listener.c
  15. +2 −1 contrib/smbfs/lib/smb/file.c
  16. +2 −1 contrib/smbfs/lib/smb/kiconv.c
  17. +1 −1 contrib/smbfs/lib/smb/nb_net.c
  18. +5 −4 contrib/smbfs/lib/smb/nls.c
  19. +2 −1 contrib/smbfs/lib/smb/rap.c
  20. +1 −0 contrib/smbfs/lib/smb/rq.c
  21. +1 −0 contrib/tcp_wrappers/options.c
  22. +1 −0 contrib/tcp_wrappers/shell_cmd.c
  23. +1 −0 gnu/lib/libdialog/rc.c
  24. +1 −0 gnu/usr.bin/sort/getopt.c
  25. +5 −0 lib/libc/gen/nlist.c
  26. +1 −1 lib/libc_r/uthread/uthread_sig.c
  27. +13 −8 lib/libcompat/4.3/rexec.c
  28. +4 −2 lib/libncp/ncpl_conn.c
  29. +3 −2 lib/libncp/ncpl_subr.c
  30. +1 −1 lib/libsctp/sctp_sys_calls.c
  31. +1 −1 lib/libthread_xu/thread/thr_private.h
  32. +7 −7 libexec/rtld-elf/debug.c
  33. +3 −3 sbin/camcontrol/camcontrol.c
  34. +1 −1 sbin/camcontrol/util.c
  35. +5 −4 sbin/diskinfo/diskinfo.c
  36. +37 −31 sbin/disklabel64/disklabel64.c
  37. +5 −4 sbin/dumpfs/dumpfs.c
  38. +2 −2 sbin/fdisk/fdisk.c
  39. +3 −3 sbin/fsdb/fsdb.c
  40. +16 −12 sbin/fsirand/fsirand.c
  41. +2 −2 sbin/growfs/growfs.c
  42. +11 −6 sbin/hammer/cmd_blockmap.c
  43. +6 −6 sbin/hammer/cmd_history.c
  44. +13 −7 sbin/hammer/cmd_info.c
  45. +45 −44 sbin/hammer/cmd_mirror.c
  46. +4 −4 sbin/hammer/cmd_pseudofs.c
  47. +12 −12 sbin/hammer/cmd_rebalance.c
  48. +11 −10 sbin/hammer/cmd_reblock.c
  49. +38 −31 sbin/hammer/cmd_show.c
  50. +1 −1 sbin/hammer/cmd_snapshot.c
  51. +13 −12 sbin/hammer/cmd_softprune.c
  52. +16 −15 sbin/hammer/cmd_stats.c
  53. +1 −1 sbin/hammer/cmd_synctid.c
  54. +1 −1 sbin/hammer/cycle.c
  55. +5 −5 sbin/hammer/hammer.c
  56. +7 −6 sbin/jscan/dump_debug.c
  57. +3 −3 sbin/jscan/jfile.c
  58. +6 −6 sbin/jscan/jscan.c
  59. +2 −2 sbin/jscan/jsession.c
  60. +18 −6 sbin/jscan/jstream.c
  61. +1 −1 sbin/jscan/subs.c
  62. +2 −2 sbin/mountctl/mountctl.c
  63. +4 −2 sbin/quotacheck/quotacheck.c
  64. +7 −4 sbin/restore/tape.c
  65. +3 −3 sbin/savecore/savecore.c
  66. +9 −6 sbin/sysctl/sysctl.c
  67. +1 −0 secure/lib/libssh/version.c
  68. +1 −1 sys/netproto/smb/smb_dev.h
  69. +2 −2 usr.bin/cmp/misc.c
  70. +6 −3 usr.bin/cmp/regular.c
  71. +2 −1 usr.bin/cmp/special.c
  72. +1 −1 usr.bin/finger/lprint.c
  73. +1 −1 usr.bin/finger/util.c
  74. +5 −1 usr.bin/gprof/arcs.c
  75. +3 −1 usr.bin/gprof/printgprof.c
  76. +1 −1 usr.bin/limits/limits.c
  77. +1 −1 usr.bin/monitor/monitor.c
  78. +3 −3 usr.bin/tail/misc.c
  79. +3 −2 usr.bin/tail/reverse.c
  80. +9 −9 usr.bin/wc/wc.c
View
@@ -159,8 +159,10 @@ jcl(char **argv)
/*
* Bail out if the calculation of a file offset would overflow.
*/
- if (in.offset > QUAD_MAX / in.dbsz || out.offset > QUAD_MAX / out.dbsz)
+ if (in.offset > QUAD_MAX / (ssize_t)in.dbsz ||
+ out.offset > QUAD_MAX / (ssize_t)out.dbsz) {
errx(1, "seek offsets cannot be larger than %lld", QUAD_MAX);
+ }
}
static int
@@ -178,7 +180,7 @@ f_bs(char *arg)
res = get_num(arg);
if (res < 1 || res > SSIZE_MAX)
- errx(1, "bs must be between 1 and %d", SSIZE_MAX);
+ errx(1, "bs must be between 1 and %zd", SSIZE_MAX);
in.dbsz = out.dbsz = (size_t)res;
}
@@ -189,7 +191,7 @@ f_cbs(char *arg)
res = get_num(arg);
if (res < 1 || res > SSIZE_MAX)
- errx(1, "cbs must be between 1 and %d", SSIZE_MAX);
+ errx(1, "cbs must be between 1 and %zd", SSIZE_MAX);
cbsz = (size_t)res;
}
@@ -221,7 +223,7 @@ f_ibs(char *arg)
if (!(ddflags & C_BS)) {
res = get_num(arg);
if (res < 1 || res > SSIZE_MAX)
- errx(1, "ibs must be between 1 and %d", SSIZE_MAX);
+ errx(1, "ibs must be between 1 and %zd", SSIZE_MAX);
in.dbsz = (size_t)res;
}
}
@@ -241,7 +243,7 @@ f_obs(char *arg)
if (!(ddflags & C_BS)) {
res = get_num(arg);
if (res < 1 || res > SSIZE_MAX)
- errx(1, "obs must be between 1 and %d", SSIZE_MAX);
+ errx(1, "obs must be between 1 and %zd", SSIZE_MAX);
out.dbsz = (size_t)res;
}
}
View
@@ -60,22 +60,25 @@ summary(void)
secs = 1e-6;
/* Use snprintf(3) so that we don't reenter stdio(3). */
snprintf(buf, sizeof(buf),
- "%llu+%llu records in\n%llu+%llu records out\n",
- st.in_full, st.in_part, st.out_full, st.out_part);
+ "%ju+%ju records in\n%ju+%ju records out\n",
+ (uintmax_t)st.in_full, (uintmax_t)st.in_part,
+ (uintmax_t)st.out_full, (uintmax_t)st.out_part);
write(STDERR_FILENO, buf, strlen(buf));
if (st.swab) {
- snprintf(buf, sizeof(buf), "%llu odd length swab %s\n",
- st.swab, (st.swab == 1) ? "block" : "blocks");
+ snprintf(buf, sizeof(buf), "%ju odd length swab %s\n",
+ (uintmax_t)st.swab,
+ ((st.swab == 1) ? "block" : "blocks"));
write(STDERR_FILENO, buf, strlen(buf));
}
if (st.trunc) {
- snprintf(buf, sizeof(buf), "%llu truncated %s\n",
- st.trunc, (st.trunc == 1) ? "block" : "blocks");
+ snprintf(buf, sizeof(buf), "%ju truncated %s\n",
+ (uintmax_t)st.trunc,
+ ((st.trunc == 1) ? "block" : "blocks"));
write(STDERR_FILENO, buf, strlen(buf));
}
snprintf(buf, sizeof(buf),
- "%llu bytes transferred in %.6f secs (%.0f bytes/sec)\n",
- st.bytes, secs, st.bytes / secs);
+ "%ju bytes transferred in %.6f secs (%.0f bytes/sec)\n",
+ (uintmax_t)st.bytes, secs, st.bytes / secs);
write(STDERR_FILENO, buf, strlen(buf));
}
View
@@ -385,7 +385,7 @@ digit_convert(void)
for (p = digit ; *p && *p != i ; p++);
if (*p == '\0')
p = digit;
- fprintf(cfile, " %d,\n", p - digit);
+ fprintf(cfile, " %td,\n", p - digit);
}
fputs("};\n", cfile);
}
View
@@ -38,6 +38,7 @@
* $DragonFly: src/bin/sh/parser.c,v 1.12 2007/01/18 17:03:18 corecode Exp $
*/
+#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
View
@@ -43,6 +43,8 @@ RCSID("$Id: getarg.c,v 1.25 1998/11/22 09:45:05 assar Exp $");
#include <sys/ttycom.h>
#include <time.h>
#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
#include "getarg.h"
#define ISFLAG(X) ((X).type == arg_flag || (X).type == arg_negative_flag)
@@ -175,7 +177,8 @@ arg_printusage (struct getargs *args,
static void
add_string(getarg_strings *s, char *value)
{
- s->strings = realloc(s->strings, (s->num_strings + 1) * sizeof(*s->strings));
+ s->strings = realloc(s->strings,
+ (s->num_strings + 1) * sizeof(*s->strings));
s->strings[s->num_strings] = value;
s->num_strings++;
}
@@ -51,11 +51,7 @@
/* Some platforms apparently define the udata field of struct kevent as
* ntptr_t, whereas others define it as void*. There doesn't seem to be an
* easy way to tell them apart via autoconf, so we need to use OS macros. */
-#if defined(HAVE_INTTYPES_H) && !defined(__OpenBSD__) && !defined(__FreeBSD__) && !defined(__darwin__) && !defined(__APPLE__)
-#define PTR_TO_UDATA(x) ((intptr_t)(x))
-#else
-#define PTR_TO_UDATA(x) (x)
-#endif
+#define PTR_TO_UDATA(x) ((void *)(x))
#include "event.h"
#include "log.h"
@@ -45,7 +45,7 @@ NCURSES_EXPORT(char *)
_tracechar(int ch)
{
static char result[40];
- char *name;
+ const char *name;
if (ch > KEY_MIN || ch < 0) {
name = keyname(ch);
@@ -34,6 +34,7 @@ you didn't get a copy, you may request one from <license@inner.net>.
*/
#include "opie_cfg.h"
+#include <stdio.h>
#if HAVE_STRING_H
#include <string.h>
#endif /* HAVE_STRING_H */
@@ -13,6 +13,7 @@ you didn't get a copy, you may request one from <license@inner.net>.
#include "opie_cfg.h"
#include <stdio.h>
+#include <string.h>
#include "opie.h"
int opielookup FUNCTION((opie, principal), struct opie *opie AND char *principal)
@@ -19,6 +19,7 @@ you didn't get a copy, you may request one from <license@inner.net>.
*/
#include "opie_cfg.h"
+#include <stdio.h>
#if HAVE_TIME_H
#include <time.h>
#endif /* HAVE_TIME_H */
@@ -20,6 +20,7 @@ you didn't get a copy, you may request one from <license@inner.net>.
Created by cmetz for OPIE 2.22.
*/
+#include <string.h>
#include "opie_cfg.h"
#include "opie.h"
@@ -26,6 +26,8 @@ License Agreement applies to this software.
Created at NRL for OPIE 2.2 from opiesubr2.c
*/
+#include <stdio.h>
+#include <string.h>
#include "opie_cfg.h"
#include "opie.h"
@@ -17,6 +17,8 @@ License Agreement applies to this software.
Modified by cmetz for OPIE 2.2. Use FUNCTION declaration et al.
Created at NRL for OPIE 2.2 from opiesubr.c.
*/
+#include <stdio.h>
+#include <stdlib.h>
#include "opie_cfg.h"
#include "opie.h"
@@ -576,7 +576,7 @@ mi_thread_handle_wrapper(arg)
** is not used anywhere.
*/
- return (void *) mi_handle_session(arg);
+ return (void *)(intptr_t)mi_handle_session(arg);
}
#endif /* _FFR_WORKERS_POOL */
@@ -32,6 +32,7 @@
* $Id: file.c,v 1.2 2001/04/16 04:33:01 bp Exp $
*/
#include <sys/param.h>
+#include <sys/cdefs.h>
#include <sys/sysctl.h>
#include <sys/ioctl.h>
#include <sys/time.h>
@@ -71,7 +72,7 @@ smb_write(struct smb_ctx *ctx, smbfh fh, off_t offset, size_t count,
struct smbioc_rw rwrq;
rwrq.ioc_fh = fh;
- rwrq.ioc_base = src;
+ rwrq.ioc_base = __DECONST(char *, src);
rwrq.ioc_cnt = count;
rwrq.ioc_offset = offset;
if (ioctl(ctx->ct_fd, SMBIOC_WRITE, &rwrq) == -1)
@@ -36,6 +36,7 @@
#include <sys/iconv.h>
#include <sys/sysctl.h>
#include <ctype.h>
+#include <string.h>
#include <errno.h>
#ifdef APPLE
@@ -48,7 +49,7 @@ kiconv_add_xlat_table(const char *to, const char *from, const u_char *table)
{
struct iconv_add_in din;
struct iconv_add_out dout;
- int olen;
+ size_t olen;
if (strlen(from) > ICONV_CSNMAXLEN || strlen(to) > ICONV_CSNMAXLEN)
return EINVAL;
@@ -198,4 +198,4 @@ nb_hostlookup(struct nb_name *np, const char *server, const char *hint,
nb_snbfree(snb);
return error;
}
-*/
+*/
@@ -41,6 +41,7 @@
#endif
#include <errno.h>
#include <stdio.h>
+#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include <locale.h>
@@ -125,7 +126,7 @@ char *
nls_str_toloc(char *dst, const char *src)
{
char *p = dst;
- int inlen, outlen;
+ size_t inlen, outlen;
if (!iconv_loaded)
return strcpy(dst, src);
@@ -147,7 +148,7 @@ char *
nls_str_toext(char *dst, const char *src)
{
char *p = dst;
- int inlen, outlen;
+ size_t inlen, outlen;
if (!iconv_loaded)
return strcpy(dst, src);
@@ -170,7 +171,7 @@ nls_mem_toloc(void *dst, const void *src, int size)
{
char *p = dst;
const char *s = src;
- int inlen, outlen;
+ size_t inlen, outlen;
if (!iconv_loaded)
return memcpy(dst, src, size);
@@ -195,7 +196,7 @@ nls_mem_toext(void *dst, const void *src, int size)
{
char *p = dst;
const char *s = src;
- int inlen, outlen;
+ size_t inlen, outlen;
if (size == 0)
return NULL;
@@ -40,6 +40,7 @@
#include <err.h>
#include <stdio.h>
#include <unistd.h>
+#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include <sysexits.h>
@@ -198,7 +199,7 @@ smb_rap_create(int fn, const char *param, const char *data,
rap = malloc(sizeof(*rap));
if (rap == NULL)
- return NULL;
+ return ENOMEM;
bzero(rap, sizeof(*rap));
p = rap->r_sparam = rap->r_nparam = strdup(param);
rap->r_sdata = rap->r_ndata = strdup(data);
@@ -39,6 +39,7 @@
#include <err.h>
#include <stdio.h>
#include <unistd.h>
+#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include <sysexits.h>
@@ -41,6 +41,7 @@ static char sccsid[] = "@(#) options.c 1.17 96/02/11 17:01:31";
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
+#include <unistd.h>
#define SYSLOG_NAMES
#include <syslog.h>
#include <pwd.h>
@@ -18,6 +18,7 @@ static char sccsid[] = "@(#) shell_cmd.c 1.5 94/12/28 17:42:44";
#include <sys/param.h>
#include <signal.h>
#include <stdio.h>
+#include <unistd.h>
#include <syslog.h>
#include <string.h>
View
@@ -245,6 +245,7 @@ static int str_to_attr(unsigned char *str, int *fg, int *bg, int *hl)
strcpy(tempstr, str + 1);
lastch(tempstr) = '\0';
+ *fg = 0; /* fix compiler warning */
/* get foreground and background */
@@ -39,6 +39,7 @@
#endif
#include <stdio.h>
+#include <string.h>
/* Comment out all this code if we are using the GNU C Library, and are not
actually compiling the library itself. This code is part of the GNU C
View
@@ -256,11 +256,13 @@ __elf_fdnlist(int fd, struct nlist *list)
/* calculate section header table size */
shdr_size = ehdr.e_shentsize * ehdr.e_shnum;
+#ifndef __amd64__
/* Make sure it's not too big to mmap */
if (shdr_size > SIZE_T_MAX) {
errno = EFBIG;
return (-1);
}
+#endif
/* mmap section header table */
base = mmap(NULL, (size_t)shdr_size, PROT_READ, 0, fd,
@@ -285,11 +287,14 @@ __elf_fdnlist(int fd, struct nlist *list)
}
}
+#ifndef __amd64__
/* Check for files too large to mmap. */
if (symstrsize > SIZE_T_MAX) {
errno = EFBIG;
goto done;
}
+#endif
+
/*
* Map string table into our address space. This gives us
* an easy way to randomly access all the strings, without
@@ -283,7 +283,7 @@ thread_sig_invoke_handler(int sig, siginfo_t *info, ucontext_t *ucp)
(info == NULL))
(*(sigfunc))(sig, info, ucp);
else
- (*(sigfunc))(sig, (siginfo_t *)info->si_code, ucp);
+ (*(sigfunc))(sig, (siginfo_t *)(intptr_t)info->si_code, ucp);
}
/*
* Only restore the signal mask if it hasn't been changed by the
Oops, something went wrong.

0 comments on commit a276dc6

Please sign in to comment.