Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* posix/wordexp.c (w_addword): Free word if realloc fails and it
	was allocated here.  [Coverity CID 219]

	* posix/getconf.c (print_all): Free confstr data after printing.
	[Coverity CID 218]

	* sysdeps/posix/getaddrinfo.c (gaih_inet): Free canon string if
	list allocation fails.  [Coverity CID 215]

	* nss/nsswitch.c (__nss_configure_lookup): Fix loop end condition.
	[Coverity CID 213]

	* argp/argp-help.c (hol_entry_cmp): Don't call canon_doc_option if
	string is NULL.  [Coverity CID 212]
	* argp/Makefile: Add rules to build and run bug-argp1.
	* argp/bug-argp1.c: New file.

	* io/ftw.c (ftw_dir): Use __rawmemchr instead of strchr to find
	end of string.
	* stdlib/canonicalize.c (__realpath): Likewise.

	* locale/programs/ld-time.c (time_finish): Don't dereference NULL
	pointer.  [Coverity CID 206]

	* elf/dl-dst.h (DL_DST_REQUIRED): Be prepared for missing link map
	in statically linked code.
	* elf/dl-load.c (_dl_dst_substitute): When replacing ORIGIN in
	statically built code, be prepared to have no link map.
	[Coverity CID 205]

	* argp/argp-help.c (fill_in_uparams): Handle STATE==NULL in
	dgettext calls. [Coverity CID 204]

	* argp/argp-help.c (struct uparams): Remove valid member.  Change
	the one user.
	(uparam_names): Reduce size.  Avoid relative relocations.
	Moved to read-only segment.
	(fill_in_uparams): Update for new layout.

	* sysdeps/unix/sysv/linux/ifaddrs.c (getifaddrs): Parameter can be
	assumed to always be != NULL. [Coverity CID 202]

	* argp/argp-help.c (hol_entry_help): Remove some dead code
	[Coverity CID 200].

	* nis/nss_nis/nis-service.c (_nss_nis_getservbyport_r): Optimize
	away a few more unconditional yperr2nss calls.
	(_nss_nis_getservbyname_r): Likewise.
  • Loading branch information
Ulrich Drepper committed May 10, 2006
1 parent be434a7 commit e7c8359
Show file tree
Hide file tree
Showing 16 changed files with 182 additions and 72 deletions.
51 changes: 51 additions & 0 deletions ChangeLog
@@ -1,3 +1,54 @@
2006-05-09 Ulrich Drepper <drepper@redhat.com>

* posix/wordexp.c (w_addword): Free word if realloc fails and it
was allocated here. [Coverity CID 219]

* posix/getconf.c (print_all): Free confstr data after printing.
[Coverity CID 218]

* sysdeps/posix/getaddrinfo.c (gaih_inet): Free canon string if
list allocation fails. [Coverity CID 215]

* nss/nsswitch.c (__nss_configure_lookup): Fix loop end condition.
[Coverity CID 213]

* argp/argp-help.c (hol_entry_cmp): Don't call canon_doc_option if
string is NULL. [Coverity CID 212]
* argp/Makefile: Add rules to build and run bug-argp1.
* argp/bug-argp1.c: New file.

* io/ftw.c (ftw_dir): Use __rawmemchr instead of strchr to find
end of string.
* stdlib/canonicalize.c (__realpath): Likewise.

* locale/programs/ld-time.c (time_finish): Don't dereference NULL
pointer. [Coverity CID 206]

* elf/dl-dst.h (DL_DST_REQUIRED): Be prepared for missing link map
in statically linked code.
* elf/dl-load.c (_dl_dst_substitute): When replacing ORIGIN in
statically built code, be prepared to have no link map.
[Coverity CID 205]

* argp/argp-help.c (fill_in_uparams): Handle STATE==NULL in
dgettext calls. [Coverity CID 204]

* argp/argp-help.c (struct uparams): Remove valid member. Change
the one user.
(uparam_names): Reduce size. Avoid relative relocations.
Moved to read-only segment.
(fill_in_uparams): Update for new layout.

* sysdeps/unix/sysv/linux/ifaddrs.c (getifaddrs): Parameter can be
assumed to always be != NULL. [Coverity CID 202]

* argp/argp-help.c (hol_entry_help): Remove some dead code
[Coverity CID 200].

* nis/nss_nis/nis-service.c (_nss_nis_getservbyport_r): Optimize
away a few more unconditional yperr2nss calls.
(_nss_nis_getservbyname_r): Likewise.

2006-05-06 Ulrich Drepper <drepper@redhat.com>

* sysdeps/generic/ldsodefs.h: Remove support for non-core
Expand Down
6 changes: 4 additions & 2 deletions argp/Makefile
@@ -1,4 +1,4 @@
# Copyright (C) 1997, 2002, 2003 Free Software Foundation, Inc.
# Copyright (C) 1997, 2002, 2003, 2006 Free Software Foundation, Inc.
# This file is part of the GNU C Library.

# The GNU C Library is free software; you can redistribute it and/or
Expand Down Expand Up @@ -26,10 +26,12 @@ distribute = argp-fmtstream.h argp-namefrob.h
routines = $(addprefix argp-, ba fmtstream fs-xinl help parse pv \
pvh xinl eexst)

tests = argp-test tst-argp1
tests = argp-test tst-argp1 bug-argp1

CFLAGS-argp-help.c = $(uses-callbacks) -fexceptions
CFLAGS-argp-parse.c = $(uses-callbacks)
CFLAGS-argp-fmtstream.c = -fexceptions

bug-argp1-ARGS = -- --help

include ../Rules
64 changes: 30 additions & 34 deletions argp/argp-help.c
@@ -1,5 +1,5 @@
/* Hierarchial argument parsing help output
Copyright (C) 1995-2003, 2004, 2005 Free Software Foundation, Inc.
Copyright (C) 1995-2003, 2004, 2005, 2006 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Written by Miles Bader <miles@gnu.ai.mit.edu>.
Expand Down Expand Up @@ -128,40 +128,37 @@ struct uparams
int header_col;
int usage_indent;
int rmargin;

int valid; /* True when the values in here are valid. */
};

/* This is a global variable, as user options are only ever read once. */
static struct uparams uparams = {
DUP_ARGS, DUP_ARGS_NOTE,
SHORT_OPT_COL, LONG_OPT_COL, DOC_OPT_COL, OPT_DOC_COL, HEADER_COL,
USAGE_INDENT, RMARGIN,
0
USAGE_INDENT, RMARGIN
};

/* A particular uparam, and what the user name is. */
struct uparam_name
{
const char *name; /* User name. */
int is_bool; /* Whether it's `boolean'. */
size_t uparams_offs; /* Location of the (int) field in UPARAMS. */
const char name[14]; /* User name. */
bool is_bool; /* Whether it's `boolean'. */
uint8_t uparams_offs; /* Location of the (int) field in UPARAMS. */
};

/* The name-field mappings we know about. */
static const struct uparam_name uparam_names[] =
{
{ "dup-args", 1, offsetof (struct uparams, dup_args) },
{ "dup-args-note", 1, offsetof (struct uparams, dup_args_note) },
{ "short-opt-col", 0, offsetof (struct uparams, short_opt_col) },
{ "long-opt-col", 0, offsetof (struct uparams, long_opt_col) },
{ "doc-opt-col", 0, offsetof (struct uparams, doc_opt_col) },
{ "opt-doc-col", 0, offsetof (struct uparams, opt_doc_col) },
{ "header-col", 0, offsetof (struct uparams, header_col) },
{ "usage-indent", 0, offsetof (struct uparams, usage_indent) },
{ "rmargin", 0, offsetof (struct uparams, rmargin) },
{ 0 }
{ "dup-args", true, offsetof (struct uparams, dup_args) },
{ "dup-args-note", true, offsetof (struct uparams, dup_args_note) },
{ "short-opt-col", false, offsetof (struct uparams, short_opt_col) },
{ "long-opt-col", false, offsetof (struct uparams, long_opt_col) },
{ "doc-opt-col", false, offsetof (struct uparams, doc_opt_col) },
{ "opt-doc-col", false, offsetof (struct uparams, opt_doc_col) },
{ "header-col", false, offsetof (struct uparams, header_col) },
{ "usage-indent", false, offsetof (struct uparams, usage_indent) },
{ "rmargin", false, offsetof (struct uparams, rmargin) }
};
#define nuparam_names (sizeof (uparam_names) / sizeof (uparam_names[0]))

/* Read user options from the environment, and fill in UPARAMS appropiately. */
static void
Expand Down Expand Up @@ -217,22 +214,27 @@ fill_in_uparams (const struct argp_state *state)
SKIPWS (arg);
}

for (un = uparam_names; un->name; un++)
un = uparam_names;
size_t u;
for (u = 0; u < nuparam_names; ++un, ++u)
if (strlen (un->name) == var_len
&& strncmp (var, un->name, var_len) == 0)
{
if (unspec && !un->is_bool)
__argp_failure (state, 0, 0,
dgettext (state->root_argp->argp_domain, "\
dgettext (state == NULL ? NULL
: state->root_argp->argp_domain,
"\
%.*s: ARGP_HELP_FMT parameter requires a value"),
(int) var_len, var);
else
*(int *)((char *)&uparams + un->uparams_offs) = val;
break;
}
if (! un->name)
if (u == nuparam_names)
__argp_failure (state, 0, 0,
dgettext (state->root_argp->argp_domain, "\
dgettext (state == NULL ? NULL
: state->root_argp->argp_domain, "\
%.*s: Unknown ARGP_HELP_FMT parameter"),
(int) var_len, var);

Expand All @@ -243,7 +245,8 @@ fill_in_uparams (const struct argp_state *state)
else if (*var)
{
__argp_failure (state, 0, 0,
dgettext (state->root_argp->argp_domain,
dgettext (state == NULL ? NULL
: state->root_argp->argp_domain,
"Garbage in ARGP_HELP_FMT: %s"), var);
break;
}
Expand Down Expand Up @@ -759,9 +762,9 @@ hol_entry_cmp (const struct hol_entry *entry1,
const char *long2 = hol_entry_first_long (entry2);

if (doc1)
doc1 = canon_doc_option (&long1);
doc1 = long1 != NULL && canon_doc_option (&long1);
if (doc2)
doc2 = canon_doc_option (&long2);
doc2 = long2 != NULL && canon_doc_option (&long2);

if (doc1 != doc2)
/* `documentation' options always follow normal options (or
Expand Down Expand Up @@ -1129,19 +1132,13 @@ hol_entry_help (struct hol_entry *entry, const struct argp_state *state,
else
/* A real long option. */
{
int first_long_opt = 1;

__argp_fmtstream_set_wmargin (stream, uparams.long_opt_col);
for (opt = real, num = entry->num; num > 0; opt++, num--)
if (opt->name && ovisible (opt))
{
comma (uparams.long_opt_col, &pest);
__argp_fmtstream_printf (stream, "--%s", opt->name);
if (first_long_opt || uparams.dup_args)
arg (real, "=%s", "[=%s]", state->root_argp->argp_domain,
stream);
else if (real->arg)
hhstate->suppressed_dup_arg = 1;
arg (real, "=%s", "[=%s]", state->root_argp->argp_domain, stream);
}
}

Expand Down Expand Up @@ -1555,8 +1552,7 @@ _help (const struct argp *argp, const struct argp_state *state, FILE *stream,
__flockfile (stream);
#endif

if (! uparams.valid)
fill_in_uparams (state);
fill_in_uparams (state);

fs = __argp_make_fmtstream (stream, 0, uparams.rmargin, 0);
if (! fs)
Expand Down
26 changes: 26 additions & 0 deletions argp/bug-argp1.c
@@ -0,0 +1,26 @@
#include <argp.h>


static const struct argp_option test_options[] =
{
{ NULL, 'a', NULL, OPTION_DOC, NULL },
{ NULL, 'b', NULL, OPTION_DOC, NULL },
{ NULL, 0, NULL, 0, NULL }
};

static struct argp test_argp =
{
test_options
};


static int
do_test (int argc, char *argv[])
{
int i;
argp_parse (&test_argp, argc, argv, 0, &i, NULL);
return 0;
}

#define TEST_FUNCTION do_test (argc, argv)
#include "../test-skeleton.c"
15 changes: 14 additions & 1 deletion elf/dl-dst.h
@@ -1,5 +1,5 @@
/* Handling of dynamic sring tokens.
Copyright (C) 1999, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
Copyright (C) 1999,2001,2002,2003,2004,2006 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
Expand Down Expand Up @@ -50,6 +50,7 @@
\
First get the origin string if it is not available yet. \
This can only happen for the map of the executable. */ \
DL_DST_REQ_STATIC \
if ((l)->l_origin == NULL) \
{ \
assert ((l)->l_name[0] == '\0'); \
Expand All @@ -66,6 +67,18 @@
\
__len; })

#ifdef SHARED
# define DL_DST_REQ_STATIC /* nothing */
#else
# define DL_DST_REQ_STATIC \
if ((l) == NULL) \
{ \
const char *origin = _dl_get_origin (); \
origin_len = (origin && origin != (char *) -1 ? strlen (origin) : 0); \
} \
else
#endif

#ifndef IS_IN_rtld
# define _dl_get_origin GLRO(dl_get_origin)
# define _dl_dst_substitute GLRO(dl_dst_substitute)
Expand Down
9 changes: 8 additions & 1 deletion elf/dl-load.c
Expand Up @@ -266,7 +266,14 @@ _dl_dst_substitute (struct link_map *l, const char *name, char *result,
++name;
if ((len = is_dst (start, name, "ORIGIN", is_path,
INTUSE(__libc_enable_secure))) != 0)
repl = l->l_origin;
{
#ifndef SHARED
if (l == NULL)
repl = _dl_get_origin ();
else
#endif
repl = l->l_origin;
}
else if ((len = is_dst (start, name, "PLATFORM", is_path, 0)) != 0)
repl = GLRO(dl_platform);
else if ((len = is_dst (start, name, "LIB", is_path, 0)) != 0)
Expand Down
2 changes: 1 addition & 1 deletion io/ftw.c
Expand Up @@ -526,7 +526,7 @@ ftw_dir (struct ftw_data *data, struct STAT *st, struct dir_data *old_dir)

/* Next, update the `struct FTW' information. */
++data->ftw.level;
startp = strchr (data->dirbuf, '\0');
startp = __rawmemchr (data->dirbuf, '\0');
/* There always must be a directory name. */
assert (startp != data->dirbuf);
if (startp[-1] != '/')
Expand Down
13 changes: 9 additions & 4 deletions locale/programs/ld-time.c
@@ -1,4 +1,4 @@
/* Copyright (C) 1995-2002, 2003, 2004, 2005 Free Software Foundation, Inc.
/* Copyright (C) 1995-2005, 2006 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.org>, 1995.
Expand Down Expand Up @@ -468,9 +468,14 @@ No definition for %s category found"), "LC_TIME"));
wstr = wstr ? wcschr (wstr + 1, L':') : NULL; /* end start */
wstr = wstr ? wcschr (wstr + 1, L':') : NULL; /* end end */
time->era_entries[idx].wname = (uint32_t *) wstr + 1;
wstr = wstr ? wcschr (wstr + 1, L':') : NULL; /* end name */
*wstr = L'\0';
time->era_entries[idx].wformat = (uint32_t *) wstr + 1;
if (wstr != NULL)
{
wstr = wcschr (wstr + 1, L':'); /* end name */
*wstr = L'\0';
time->era_entries[idx].wformat = (uint32_t *) wstr + 1;
}
else
time->era_entries[idx].wformat = NULL;
}
}

Expand Down

0 comments on commit e7c8359

Please sign in to comment.