mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-24 22:10:13 +00:00
Realloc error handling memory leak fix.
This commit is contained in:
parent
9403ec5d23
commit
d1dddedf78
@ -247,9 +247,15 @@ __md5_crypt (const char *key, const char *salt)
|
|||||||
|
|
||||||
if (buflen < needed)
|
if (buflen < needed)
|
||||||
{
|
{
|
||||||
|
char *new_buffer;
|
||||||
|
|
||||||
buflen = needed;
|
buflen = needed;
|
||||||
if ((buffer = realloc (buffer, buflen)) == NULL)
|
|
||||||
|
new_buffer = (char *) realloc (buffer, buflen);
|
||||||
|
if (new_buffer == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
buffer = new_buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
return __md5_crypt_r (key, salt, buffer, buflen);
|
return __md5_crypt_r (key, salt, buffer, buflen);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* Return the canonical absolute name of a given file inside chroot.
|
/* Return the canonical absolute name of a given file inside chroot.
|
||||||
Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
|
Copyright (C) 1996,1997,1998,1999,2000,2001 Free Software Foundation, Inc.
|
||||||
This file is part of the GNU C Library.
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
The GNU C Library is free software; you can redistribute it and/or
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
@ -42,8 +42,13 @@
|
|||||||
char *
|
char *
|
||||||
chroot_canon (const char *chroot, const char *name)
|
chroot_canon (const char *chroot, const char *name)
|
||||||
{
|
{
|
||||||
char *rpath, *dest, *extra_buf = NULL, *rpath_root;
|
char *rpath;
|
||||||
const char *start, *end, *rpath_limit;
|
char *dest;
|
||||||
|
char *extra_buf = NULL;
|
||||||
|
char *rpath_root;
|
||||||
|
const char *start;
|
||||||
|
const char *end;
|
||||||
|
const char *rpath_limit;
|
||||||
int num_links = 0;
|
int num_links = 0;
|
||||||
size_t chroot_len = strlen (chroot);
|
size_t chroot_len = strlen (chroot);
|
||||||
|
|
||||||
@ -94,16 +99,18 @@ chroot_canon (const char *chroot, const char *name)
|
|||||||
if (dest + (end - start) >= rpath_limit)
|
if (dest + (end - start) >= rpath_limit)
|
||||||
{
|
{
|
||||||
ptrdiff_t dest_offset = dest - rpath;
|
ptrdiff_t dest_offset = dest - rpath;
|
||||||
|
char *new_rpath;
|
||||||
|
|
||||||
new_size = rpath_limit - rpath;
|
new_size = rpath_limit - rpath;
|
||||||
if (end - start + 1 > PATH_MAX)
|
if (end - start + 1 > PATH_MAX)
|
||||||
new_size += end - start + 1;
|
new_size += end - start + 1;
|
||||||
else
|
else
|
||||||
new_size += PATH_MAX;
|
new_size += PATH_MAX;
|
||||||
rpath = realloc (rpath, new_size);
|
new_rpath = (char *) realloc (rpath, new_size);
|
||||||
rpath_limit = rpath + new_size;
|
if (new_rpath == NULL)
|
||||||
if (rpath == NULL)
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
rpath = new_rpath;
|
||||||
|
rpath_limit = rpath + new_size;
|
||||||
|
|
||||||
dest = rpath + dest_offset;
|
dest = rpath + dest_offset;
|
||||||
}
|
}
|
||||||
|
@ -121,11 +121,16 @@ _dl_new_object (char *realname, const char *libname, int type,
|
|||||||
origin = NULL;
|
origin = NULL;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
char *new_origin;
|
||||||
|
|
||||||
len += 128;
|
len += 128;
|
||||||
origin = (char *) realloc (origin, len);
|
new_origin = (char *) realloc (origin, len);
|
||||||
|
if (new_origin == NULL)
|
||||||
|
/* We exit the loop. Note that result == NULL. */
|
||||||
|
break;
|
||||||
|
origin = new_origin;
|
||||||
}
|
}
|
||||||
while (origin != NULL
|
while ((result = __getcwd (origin, len - realname_len)) == NULL
|
||||||
&& (result = __getcwd (origin, len - realname_len)) == NULL
|
|
||||||
&& errno == ERANGE);
|
&& errno == ERANGE);
|
||||||
|
|
||||||
if (result == NULL)
|
if (result == NULL)
|
||||||
|
@ -483,7 +483,7 @@ incomplete character or shift sequence at end of buffer"));
|
|||||||
static int
|
static int
|
||||||
process_fd (struct convtable *tbl, int fd, FILE *output)
|
process_fd (struct convtable *tbl, int fd, FILE *output)
|
||||||
{
|
{
|
||||||
/* we have a problem with reading from a desriptor since we must not
|
/* We have a problem with reading from a descriptor since we must not
|
||||||
provide the iconv() function an incomplete character or shift
|
provide the iconv() function an incomplete character or shift
|
||||||
sequence at the end of the buffer. Since we have to deal with
|
sequence at the end of the buffer. Since we have to deal with
|
||||||
arbitrary encodings we must read the whole text in a buffer and
|
arbitrary encodings we must read the whole text in a buffer and
|
||||||
@ -516,12 +516,17 @@ process_fd (struct convtable *tbl, int fd, FILE *output)
|
|||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
ssize_t n;
|
ssize_t n;
|
||||||
|
char *new_inbuf;
|
||||||
|
|
||||||
/* Increase the buffer. */
|
/* Increase the buffer. */
|
||||||
|
new_inbuf = (char *) realloc (inbuf, maxlen + 32768);
|
||||||
|
if (new_inbuf == NULL)
|
||||||
|
{
|
||||||
|
error (0, errno, _("unable to allocate buffer for input"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
inbuf = new_inbuf;
|
||||||
maxlen += 32768;
|
maxlen += 32768;
|
||||||
inbuf = realloc (inbuf, maxlen);
|
|
||||||
if (inbuf == NULL)
|
|
||||||
error (0, errno, _("unable to allocate buffer for input"));
|
|
||||||
inptr = inbuf + actlen;
|
inptr = inbuf + actlen;
|
||||||
|
|
||||||
do
|
do
|
||||||
|
@ -516,12 +516,17 @@ process_fd (iconv_t cd, int fd, FILE *output)
|
|||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
ssize_t n;
|
ssize_t n;
|
||||||
|
char *new_inbuf;
|
||||||
|
|
||||||
/* Increase the buffer. */
|
/* Increase the buffer. */
|
||||||
|
new_inbuf = (char *) realloc (inbuf, maxlen + 32768);
|
||||||
|
if (new_inbuf == NULL)
|
||||||
|
{
|
||||||
|
error (0, errno, _("unable to allocate buffer for input"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
inbuf = new_inbuf;
|
||||||
maxlen += 32768;
|
maxlen += 32768;
|
||||||
inbuf = realloc (inbuf, maxlen);
|
|
||||||
if (inbuf == NULL)
|
|
||||||
error (0, errno, _("unable to allocate buffer for input"));
|
|
||||||
inptr = inbuf + actlen;
|
inptr = inbuf + actlen;
|
||||||
|
|
||||||
do
|
do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (C) 1994, 1996, 1997, 1998 Free Software Foundation, Inc.
|
/* Copyright (C) 1994, 1996, 1997, 1998, 2001 Free Software Foundation, Inc.
|
||||||
This file is part of the GNU C Library.
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
The GNU C Library is free software; you can redistribute it and/or
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
@ -96,15 +96,18 @@ _IO_getdelim (lineptr, n, delimiter, fp)
|
|||||||
needed = cur_len + len + 1;
|
needed = cur_len + len + 1;
|
||||||
if (needed > *n)
|
if (needed > *n)
|
||||||
{
|
{
|
||||||
|
char *new_lineptr;
|
||||||
|
|
||||||
if (needed < 2 * *n)
|
if (needed < 2 * *n)
|
||||||
needed = 2 * *n; /* Be generous. */
|
needed = 2 * *n; /* Be generous. */
|
||||||
*n = needed;
|
new_lineptr = (char *) realloc (*lineptr, needed);
|
||||||
*lineptr = (char *) realloc (*lineptr, needed);
|
if (new_lineptr == NULL)
|
||||||
if (*lineptr == NULL)
|
|
||||||
{
|
{
|
||||||
result = -1;
|
result = -1;
|
||||||
goto unlock_return;
|
goto unlock_return;
|
||||||
}
|
}
|
||||||
|
*lineptr = new_lineptr;
|
||||||
|
*n = needed;
|
||||||
}
|
}
|
||||||
memcpy (*lineptr + cur_len, (void *) fp->_IO_read_ptr, len);
|
memcpy (*lineptr + cur_len, (void *) fp->_IO_read_ptr, len);
|
||||||
fp->_IO_read_ptr += len;
|
fp->_IO_read_ptr += len;
|
||||||
|
@ -74,12 +74,16 @@ _nl_init_era_entries (void)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
struct era_entry *new_eras = eras;
|
||||||
|
|
||||||
if (num_eras != new_num_eras)
|
if (num_eras != new_num_eras)
|
||||||
eras = (struct era_entry *) realloc (eras,
|
new_eras =
|
||||||
new_num_eras
|
(struct era_entry *) realloc (eras,
|
||||||
* sizeof (struct era_entry));
|
new_num_eras
|
||||||
if (eras == NULL)
|
* sizeof (struct era_entry));
|
||||||
|
if (new_eras == NULL)
|
||||||
{
|
{
|
||||||
|
free (eras);
|
||||||
num_eras = 0;
|
num_eras = 0;
|
||||||
eras = NULL;
|
eras = NULL;
|
||||||
}
|
}
|
||||||
@ -87,6 +91,7 @@ _nl_init_era_entries (void)
|
|||||||
{
|
{
|
||||||
const char *ptr = _NL_CURRENT (LC_TIME, _NL_TIME_ERA_ENTRIES);
|
const char *ptr = _NL_CURRENT (LC_TIME, _NL_TIME_ERA_ENTRIES);
|
||||||
num_eras = new_num_eras;
|
num_eras = new_num_eras;
|
||||||
|
eras = new_eras;
|
||||||
|
|
||||||
for (cnt = 0; cnt < num_eras; ++cnt)
|
for (cnt = 0; cnt < num_eras; ++cnt)
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* Return the canonical absolute name of a given file.
|
/* Return the canonical absolute name of a given file.
|
||||||
Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
|
Copyright (C) 1996,1997,1998,1999,2000,2001 Free Software Foundation, Inc.
|
||||||
This file is part of the GNU C Library.
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
The GNU C Library is free software; you can redistribute it and/or
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
@ -122,6 +122,7 @@ canonicalize (const char *name, char *resolved)
|
|||||||
if (dest + (end - start) >= rpath_limit)
|
if (dest + (end - start) >= rpath_limit)
|
||||||
{
|
{
|
||||||
ptrdiff_t dest_offset = dest - rpath;
|
ptrdiff_t dest_offset = dest - rpath;
|
||||||
|
char *new_rpath;
|
||||||
|
|
||||||
if (resolved)
|
if (resolved)
|
||||||
{
|
{
|
||||||
@ -136,10 +137,11 @@ canonicalize (const char *name, char *resolved)
|
|||||||
new_size += end - start + 1;
|
new_size += end - start + 1;
|
||||||
else
|
else
|
||||||
new_size += path_max;
|
new_size += path_max;
|
||||||
rpath = realloc (rpath, new_size);
|
new_rpath = (char *) realloc (rpath, new_size);
|
||||||
|
if (new_rpath == NULL)
|
||||||
|
goto error;
|
||||||
|
rpath = new_rpath;
|
||||||
rpath_limit = rpath + new_size;
|
rpath_limit = rpath + new_size;
|
||||||
if (rpath == NULL)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
dest = rpath + dest_offset;
|
dest = rpath + dest_offset;
|
||||||
}
|
}
|
||||||
|
12
sunrpc/svc.c
12
sunrpc/svc.c
@ -86,6 +86,8 @@ xprt_register (SVCXPRT *xprt)
|
|||||||
|
|
||||||
if (sock < _rpc_dtablesize ())
|
if (sock < _rpc_dtablesize ())
|
||||||
{
|
{
|
||||||
|
struct pollfd *new_svc_pollfd;
|
||||||
|
|
||||||
xports[sock] = xprt;
|
xports[sock] = xprt;
|
||||||
if (sock < FD_SETSIZE)
|
if (sock < FD_SETSIZE)
|
||||||
FD_SET (sock, &svc_fdset);
|
FD_SET (sock, &svc_fdset);
|
||||||
@ -100,11 +102,13 @@ xprt_register (SVCXPRT *xprt)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
++svc_max_pollfd;
|
new_svc_pollfd = (struct pollfd *) realloc (svc_pollfd,
|
||||||
svc_pollfd = realloc (svc_pollfd,
|
sizeof (struct pollfd)
|
||||||
sizeof (struct pollfd) * svc_max_pollfd);
|
* (svc_max_pollfd + 1));
|
||||||
if (svc_pollfd == NULL) /* Out of memory */
|
if (new_svc_pollfd == NULL) /* Out of memory */
|
||||||
return;
|
return;
|
||||||
|
svc_pollfd = new_svc_pollfd;
|
||||||
|
++svc_max_pollfd;
|
||||||
|
|
||||||
svc_pollfd[svc_max_pollfd - 1].fd = sock;
|
svc_pollfd[svc_max_pollfd - 1].fd = sock;
|
||||||
svc_pollfd[svc_max_pollfd - 1].events = (POLLIN | POLLPRI |
|
svc_pollfd[svc_max_pollfd - 1].events = (POLLIN | POLLPRI |
|
||||||
|
@ -836,28 +836,33 @@ glob (pattern, flags, errfunc, pglob)
|
|||||||
: (__stat64 (dirname, &st64) == 0 && S_ISDIR (st64.st_mode)))))
|
: (__stat64 (dirname, &st64) == 0 && S_ISDIR (st64.st_mode)))))
|
||||||
{
|
{
|
||||||
int newcount = pglob->gl_pathc + pglob->gl_offs;
|
int newcount = pglob->gl_pathc + pglob->gl_offs;
|
||||||
|
char **new_gl_pathv;
|
||||||
|
|
||||||
pglob->gl_pathv
|
new_gl_pathv
|
||||||
= (char **) realloc (pglob->gl_pathv,
|
= (char **) realloc (pglob->gl_pathv,
|
||||||
(newcount + 1 + 1) * sizeof (char *));
|
(newcount + 1 + 1) * sizeof (char *));
|
||||||
if (pglob->gl_pathv == NULL)
|
if (new_gl_pathv == NULL)
|
||||||
return GLOB_NOSPACE;
|
{
|
||||||
|
nospace:
|
||||||
|
free (pglob->gl_pathv);
|
||||||
|
pglob->gl_pathv = NULL;
|
||||||
|
pglob->gl_pathc = 0;
|
||||||
|
return GLOB_NOSPACE;
|
||||||
|
}
|
||||||
|
pglob->gl_pathv = new_gl_pathv;
|
||||||
|
|
||||||
#if defined HAVE_STRDUP || defined _LIBC
|
#if defined HAVE_STRDUP || defined _LIBC
|
||||||
pglob->gl_pathv[newcount] = strdup (dirname);
|
pglob->gl_pathv[newcount] = strdup (dirname);
|
||||||
#else
|
#else
|
||||||
{
|
{
|
||||||
size_t len = strlen (dirname) + 1;
|
size_t len = strlen (dirname) + 1;
|
||||||
char *dircopy = malloc (len);
|
char *dircopy = (char *) malloc (len);
|
||||||
if (dircopy != NULL)
|
if (dircopy != NULL)
|
||||||
pglob->gl_pathv[newcount] = memcpy (dircopy, dirname, len);
|
pglob->gl_pathv[newcount] = memcpy (dircopy, dirname, len);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (pglob->gl_pathv[newcount] == NULL)
|
if (pglob->gl_pathv[newcount] == NULL)
|
||||||
{
|
goto nospace;
|
||||||
free (pglob->gl_pathv);
|
|
||||||
return GLOB_NOSPACE;
|
|
||||||
}
|
|
||||||
pglob->gl_pathv[++newcount] = NULL;
|
pglob->gl_pathv[++newcount] = NULL;
|
||||||
++pglob->gl_pathc;
|
++pglob->gl_pathc;
|
||||||
pglob->gl_flags = flags;
|
pglob->gl_flags = flags;
|
||||||
@ -946,24 +951,24 @@ glob (pattern, flags, errfunc, pglob)
|
|||||||
|
|
||||||
/* We have ignored the GLOB_NOCHECK flag in the `glob_in_dir' calls.
|
/* We have ignored the GLOB_NOCHECK flag in the `glob_in_dir' calls.
|
||||||
But if we have not found any matching entry and the GLOB_NOCHECK
|
But if we have not found any matching entry and the GLOB_NOCHECK
|
||||||
flag was set we must return the list consisting of the disrectory
|
flag was set we must return the input pattern itself. */
|
||||||
names followed by the filename. */
|
|
||||||
if (pglob->gl_pathc + pglob->gl_offs == oldcount)
|
if (pglob->gl_pathc + pglob->gl_offs == oldcount)
|
||||||
{
|
{
|
||||||
/* No matches. */
|
/* No matches. */
|
||||||
if (flags & GLOB_NOCHECK)
|
if (flags & GLOB_NOCHECK)
|
||||||
{
|
{
|
||||||
int newcount = pglob->gl_pathc + pglob->gl_offs;
|
int newcount = pglob->gl_pathc + pglob->gl_offs;
|
||||||
|
char **new_gl_pathv;
|
||||||
|
|
||||||
pglob->gl_pathv
|
new_gl_pathv = (char **) realloc (pglob->gl_pathv,
|
||||||
= (char **) realloc (pglob->gl_pathv,
|
(newcount + 2)
|
||||||
(newcount + 2)
|
* sizeof (char *));
|
||||||
* sizeof (char *));
|
if (new_gl_pathv == NULL)
|
||||||
if (pglob->gl_pathv == NULL)
|
|
||||||
{
|
{
|
||||||
globfree (&dirs);
|
globfree (&dirs);
|
||||||
return GLOB_NOSPACE;
|
return GLOB_NOSPACE;
|
||||||
}
|
}
|
||||||
|
pglob->gl_pathv = new_gl_pathv;
|
||||||
|
|
||||||
pglob->gl_pathv[newcount] = __strdup (pattern);
|
pglob->gl_pathv[newcount] = __strdup (pattern);
|
||||||
if (pglob->gl_pathv[newcount] == NULL)
|
if (pglob->gl_pathv[newcount] == NULL)
|
||||||
@ -1386,12 +1391,15 @@ glob_in_dir (pattern, directory, flags, errfunc, pglob)
|
|||||||
|
|
||||||
if (nfound != 0)
|
if (nfound != 0)
|
||||||
{
|
{
|
||||||
pglob->gl_pathv
|
char **new_gl_pathv;
|
||||||
|
|
||||||
|
new_gl_pathv
|
||||||
= (char **) realloc (pglob->gl_pathv,
|
= (char **) realloc (pglob->gl_pathv,
|
||||||
(pglob->gl_pathc + pglob->gl_offs + nfound + 1)
|
(pglob->gl_pathc + pglob->gl_offs + nfound + 1)
|
||||||
* sizeof (char *));
|
* sizeof (char *));
|
||||||
if (pglob->gl_pathv == NULL)
|
if (new_gl_pathv == NULL)
|
||||||
goto memory_error;
|
goto memory_error;
|
||||||
|
pglob->gl_pathv = new_gl_pathv;
|
||||||
|
|
||||||
for (; names != NULL; names = names->next)
|
for (; names != NULL; names = names->next)
|
||||||
pglob->gl_pathv[pglob->gl_offs + pglob->gl_pathc++] = names->name;
|
pglob->gl_pathv[pglob->gl_offs + pglob->gl_pathc++] = names->name;
|
||||||
|
Loading…
Reference in New Issue
Block a user