Remove unapplied patches

This commit is contained in:
Florian Weimer 2016-05-09 14:19:32 +02:00
parent 43e96b9dec
commit f3507c9c60
7 changed files with 0 additions and 4189 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,13 +0,0 @@
Index: glibc-2.23-69-gf5e753c8/localedata/locales/an_ES
===================================================================
--- glibc-2.23-69-gf5e753c8.orig/localedata/locales/an_ES
+++ glibc-2.23-69-gf5e753c8/localedata/locales/an_ES
@@ -134,7 +134,7 @@ postal_fmt "<U0025><U0066><U0025><U00
country_ab2 "<U0045><U0053>"
country_ab3 "<U0045><U0053><U0050>"
country_num 724
-lang_ab "<U0041><U004E>"
+lang_ab "<U0061><U006E>"
% E
country_car "<U0045>"
% aragonés

View File

@ -1,47 +0,0 @@
commit 403ce35141da511898cde550f48ebc68a2a3ac82
Author: Siddhesh Poyarekar <siddhesh@redhat.com>
Date: Mon Jan 6 14:37:21 2014 +0530
Fix infinite loop in ftell when writing wide char data (BZ #16398)
ftell tries to avoid flushing the buffer when it is in write mode by
converting the wide char data and placing it into the binary buffer.
If the output buffer space is full and there is data to write, the
code reverts to flushing the buffer. This breaks when there is space
in the buffer but it is not enough to convert the next character in
the wide data buffer, due to which __codecvt_do_out returns a
__codecvt_partial status. In this case, ftell keeps running in an
infinite loop.
The fix here is to detect the __codecvt_partial status in addition to
checking if the buffer is full.
diff --git a/libio/wfileops.c b/libio/wfileops.c
index 87d3cdc..877fc1f 100644
--- a/libio/wfileops.c
+++ b/libio/wfileops.c
@@ -715,7 +715,7 @@ _IO_wfile_seekoff (fp, offset, dir, mode)
- fp->_wide_data->_IO_write_base) / clen;
else
{
- enum __codecvt_result status;
+ enum __codecvt_result status = __codecvt_ok;
delta = (fp->_wide_data->_IO_write_ptr
- fp->_wide_data->_IO_write_base);
const wchar_t *write_base = fp->_wide_data->_IO_write_base;
@@ -728,9 +728,12 @@ _IO_wfile_seekoff (fp, offset, dir, mode)
flush buffers for every ftell. */
do
{
- /* Ugh, no point trying to avoid the flush. Just do it
- and go back to how it was with the read mode. */
- if (delta > 0 && new_write_ptr == fp->_IO_buf_end)
+ /* There is not enough space in the buffer to do the entire
+ conversion, so there is no point trying to avoid the
+ buffer flush. Just do it and go back to how it was with
+ the read mode. */
+ if (status == __codecvt_partial
+ || (delta > 0 && new_write_ptr == fp->_IO_buf_end))
{
if (_IO_switch_to_wget_mode (fp))
return WEOF;

View File

@ -1,836 +0,0 @@
commit 03425ba6ab17b87b2c64f0d7b47fb0b86add9993
Author: Siddhesh Poyarekar <siddhesh@redhat.com>
Date: Thu Feb 20 15:41:18 2014 +0530
Separate ftell from fseek logic and avoid modifying FILE data (#16532)
ftell semantics are distinct from fseek(SEEK_CUR) especially when it
is called on a file handler that is not yet active. Due to this
caveat, much care needs to be taken while modifying the handler data
and hence, this first iteration on separating out ftell focusses on
maintaining handler data integrity at all times while it figures out
the current stream offset. The result is that it makes a syscall for
every offset request.
There is scope for optimizing this by caching offsets when we know
that the handler is active. A simple way to find out is when the
buffers have data. It is not so simple to find this out when the
buffer is empty without adding some kind of flag.
diff --git a/libio/Makefile b/libio/Makefile
index 8c333ce..8ccd80f 100644
--- a/libio/Makefile
+++ b/libio/Makefile
@@ -60,7 +60,7 @@ tests = tst_swprintf tst_wprintf tst_swscanf tst_wscanf tst_getwc tst_putwc \
tst-wmemstream1 tst-wmemstream2 \
bug-memstream1 bug-wmemstream1 \
tst-setvbuf1 tst-popen1 tst-fgetwc bug-wsetpos tst-fseek \
- tst-fwrite-error tst-ftell-partial-wide
+ tst-fwrite-error tst-ftell-partial-wide tst-ftell-active-handler
ifeq (yes,$(build-shared))
# Add test-fopenloc only if shared library is enabled since it depends on
# shared localedata objects.
diff --git a/libio/fileops.c b/libio/fileops.c
index a3499be..a177302 100644
--- a/libio/fileops.c
+++ b/libio/fileops.c
@@ -931,6 +931,59 @@ _IO_file_sync_mmap (_IO_FILE *fp)
_IO_off64_t
+get_file_offset (_IO_FILE *fp)
+{
+ if ((fp->_flags & _IO_IS_APPENDING) == _IO_IS_APPENDING)
+ {
+ struct stat64 st;
+ bool ret = (_IO_SYSSTAT (fp, &st) == 0 && S_ISREG (st.st_mode));
+ if (ret)
+ return st.st_size;
+ else
+ return EOF;
+ }
+ else
+ return _IO_SYSSEEK (fp, 0, _IO_seek_cur);
+}
+
+
+/* ftell{,o} implementation. Don't modify any state of the file pointer while
+ we try to get the current state of the stream. */
+static _IO_off64_t
+do_ftell (_IO_FILE *fp)
+{
+ _IO_off64_t result;
+
+ result = get_file_offset (fp);
+
+ if (result == EOF)
+ return result;
+
+ /* No point looking at unflushed data if we haven't allocated buffers
+ yet. */
+ if (fp->_IO_buf_base != NULL)
+ {
+ bool was_writing = (fp->_IO_write_ptr > fp->_IO_write_base
+ || _IO_in_put_mode (fp));
+
+ /* Adjust for unflushed data. */
+ if (!was_writing)
+ result -= fp->_IO_read_end - fp->_IO_read_ptr;
+ else
+ result += fp->_IO_write_ptr - fp->_IO_read_end;
+ }
+
+ if (result < 0)
+ {
+ __set_errno (EINVAL);
+ return EOF;
+ }
+
+ return result;
+}
+
+
+_IO_off64_t
_IO_new_file_seekoff (fp, offset, dir, mode)
_IO_FILE *fp;
_IO_off64_t offset;
@@ -940,6 +993,13 @@ _IO_new_file_seekoff (fp, offset, dir, mode)
_IO_off64_t result;
_IO_off64_t delta, new_offset;
long count;
+
+ /* Short-circuit into a separate function. We don't want to mix any
+ functionality and we don't want to touch anything inside the FILE
+ object. */
+ if (mode == 0)
+ return do_ftell (fp);
+
/* POSIX.1 8.2.3.7 says that after a call the fflush() the file
offset of the underlying file must be exact. */
int must_be_exact = (fp->_IO_read_base == fp->_IO_read_end
@@ -948,9 +1008,6 @@ _IO_new_file_seekoff (fp, offset, dir, mode)
bool was_writing = (fp->_IO_write_ptr > fp->_IO_write_base
|| _IO_in_put_mode (fp));
- if (mode == 0)
- dir = _IO_seek_cur, offset = 0; /* Don't move any pointers. */
-
/* Flush unwritten characters.
(This may do an unneeded write if we seek within the buffer.
But to be able to switch to reading, we would need to set
@@ -958,7 +1015,7 @@ _IO_new_file_seekoff (fp, offset, dir, mode)
which assumes file_ptr() is eGptr. Anyway, since we probably
end up flushing when we close(), it doesn't make much difference.)
FIXME: simulate mem-mapped files. */
- else if (was_writing && _IO_switch_to_get_mode (fp))
+ if (was_writing && _IO_switch_to_get_mode (fp))
return EOF;
if (fp->_IO_buf_base == NULL)
@@ -978,30 +1035,10 @@ _IO_new_file_seekoff (fp, offset, dir, mode)
{
case _IO_seek_cur:
/* Adjust for read-ahead (bytes is buffer). */
- if (mode != 0 || !was_writing)
- offset -= fp->_IO_read_end - fp->_IO_read_ptr;
- else
- {
- /* _IO_read_end coincides with fp._offset, so the actual file position
- is fp._offset - (_IO_read_end - new_write_ptr). This is fine
- even if fp._offset is not set, since fp->_IO_read_end is then at
- _IO_buf_base and this adjustment is for unbuffered output. */
- offset -= fp->_IO_read_end - fp->_IO_write_ptr;
- }
+ offset -= fp->_IO_read_end - fp->_IO_read_ptr;
if (fp->_offset == _IO_pos_BAD)
- {
- if (mode != 0)
- goto dumb;
- else
- {
- result = _IO_SYSSEEK (fp, 0, dir);
- if (result == EOF)
- return result;
-
- fp->_offset = result;
- }
- }
+ goto dumb;
/* Make offset absolute, assuming current pointer is file_ptr(). */
offset += fp->_offset;
if (offset < 0)
@@ -1028,10 +1065,6 @@ _IO_new_file_seekoff (fp, offset, dir, mode)
}
/* At this point, dir==_IO_seek_set. */
- /* If we are only interested in the current position we've found it now. */
- if (mode == 0)
- return offset;
-
/* If destination is within current buffer, optimize: */
if (fp->_offset != _IO_pos_BAD && fp->_IO_read_base != NULL
&& !_IO_in_backup (fp))
diff --git a/libio/libioP.h b/libio/libioP.h
index 4ca723c..8a7b85b 100644
--- a/libio/libioP.h
+++ b/libio/libioP.h
@@ -397,6 +397,7 @@ extern void _IO_wdoallocbuf (_IO_FILE *) __THROW;
libc_hidden_proto (_IO_wdoallocbuf)
extern void _IO_unsave_wmarkers (_IO_FILE *) __THROW;
extern unsigned _IO_adjust_wcolumn (unsigned, const wchar_t *, int) __THROW;
+extern _IO_off64_t get_file_offset (_IO_FILE *fp);
/* Marker-related function. */
diff --git a/libio/tst-ftell-active-handler.c b/libio/tst-ftell-active-handler.c
new file mode 100644
index 0000000..aac2923
--- /dev/null
+++ b/libio/tst-ftell-active-handler.c
@@ -0,0 +1,366 @@
+/* Verify that ftell returns the correct value at various points before and
+ after the handler on which it is called becomes active.
+ Copyright (C) 2014 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
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <locale.h>
+#include <wchar.h>
+
+static int do_test (void);
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
+
+#define get_handles_fdopen(filename, fd, fp, fd_mode, mode) \
+({ \
+ int ret = 0; \
+ (fd) = open ((filename), (fd_mode), 0); \
+ if ((fd) == -1) \
+ { \
+ printf ("open failed: %m\n"); \
+ ret = 1; \
+ } \
+ else \
+ { \
+ (fp) = fdopen ((fd), (mode)); \
+ if ((fp) == NULL) \
+ { \
+ printf ("fdopen failed: %m\n"); \
+ close (fd); \
+ ret = 1; \
+ } \
+ } \
+ ret; \
+})
+
+#define get_handles_fopen(filename, fd, fp, mode) \
+({ \
+ int ret = 0; \
+ (fp) = fopen ((filename), (mode)); \
+ if ((fp) == NULL) \
+ { \
+ printf ("fopen failed: %m\n"); \
+ ret = 1; \
+ } \
+ else \
+ { \
+ (fd) = fileno (fp); \
+ if ((fd) == -1) \
+ { \
+ printf ("fileno failed: %m\n"); \
+ ret = 1; \
+ } \
+ } \
+ ret; \
+})
+
+static const void *data;
+static const char *char_data = "abcdef";
+static const wchar_t *wide_data = L"abcdef";
+static size_t data_len;
+/* Maintain the current file length for validation. */
+static size_t file_len;
+
+typedef int (*fputs_func_t) (const void *data, FILE *fp);
+fputs_func_t fputs_func;
+
+/* Test that the value of ftell is not cached when the stream handle is not
+ active. */
+static int
+do_ftell_test (const char *filename)
+{
+ int ret = 0;
+ struct test
+ {
+ const char *mode;
+ int fd_mode;
+ size_t old_off;
+ size_t new_off;
+ } test_modes[] = {
+ {"w", O_WRONLY, 0, data_len},
+ {"w+", O_RDWR, 0, data_len},
+ {"r+", O_RDWR, 0, data_len},
+ {"a", O_WRONLY, data_len, 2 * data_len},
+ {"a+", O_RDWR, 2 * data_len, 3 * data_len},
+ };
+ for (int j = 0; j < 2; j++)
+ {
+ for (int i = 0; i < sizeof (test_modes) / sizeof (struct test); i++)
+ {
+ FILE *fp;
+ int fd;
+ printf ("\tftell: %s (file, \"%s\"): ", j == 0 ? "fdopen" : "fopen",
+ test_modes[i].mode);
+
+ if (j == 0)
+ ret = get_handles_fdopen (filename, fd, fp, test_modes[i].fd_mode,
+ test_modes[i].mode);
+ else
+ ret = get_handles_fopen (filename, fd, fp, test_modes[i].mode);
+
+ if (ret != 0)
+ return 1;
+
+ long off = ftell (fp);
+ if (off != test_modes[i].old_off)
+ {
+ printf ("Incorrect old offset. Expected %zu but got %ld, ",
+ test_modes[i].old_off, off);
+ ret |= 1;
+ }
+ else
+ printf ("old offset = %ld, ", off);
+
+ int ret = write (fd, data, data_len);
+ off = ftell (fp);
+
+ if (off != test_modes[i].new_off)
+ {
+ printf ("Incorrect new offset. Expected %zu but got %ld\n",
+ test_modes[i].old_off, off);
+ ret |= 1;
+ }
+ else
+ printf ("new offset = %ld\n", off);
+
+ fclose (fp);
+ }
+ }
+
+ return ret;
+}
+
+/* This test opens the file for writing, moves the file offset of the
+ underlying file, writes out data and then checks if ftell trips on it. */
+static int
+do_write_test (const char *filename)
+{
+ FILE *fp = NULL;
+ int fd;
+ int ret = 0;
+ struct test
+ {
+ const char *mode;
+ int fd_mode;
+ } test_modes[] = {
+ {"w", O_WRONLY},
+ {"w+", O_RDWR},
+ {"r+", O_RDWR}
+ };
+
+ for (int j = 0; j < 2; j++)
+ {
+ for (int i = 0; i < sizeof (test_modes) / sizeof (struct test); i++)
+ {
+ printf ("\twrite: %s (file, \"%s\"): ", j == 0 ? "fopen" : "fdopen",
+ test_modes[i].mode);
+
+ if (j == 0)
+ ret = get_handles_fopen (filename, fd, fp, test_modes[i].mode);
+ else
+ ret = get_handles_fdopen (filename, fd, fp, test_modes[i].fd_mode,
+ test_modes[i].mode);
+
+ if (ret != 0)
+ return ret;
+
+ /* Move offset to just before the end of the file. */
+ off_t ret = lseek (fd, file_len - 1, SEEK_SET);
+ if (ret == -1)
+ {
+ printf ("lseek failed: %m\n");
+ ret |= 1;
+ }
+
+ /* Write some data. */
+ size_t written = fputs_func (data, fp);
+
+ if (written == EOF)
+ {
+ printf ("fputs[1] failed to write data\n");
+ ret |= 1;
+ }
+
+ /* Verify that the offset points to the end of the file. */
+ long offset = ftell (fp);
+ file_len = file_len - 1 + data_len;
+
+ if (offset != file_len)
+ {
+ printf ("Incorrect offset. Expected %zu, but got %ld\n",
+ file_len, offset);
+
+ ret |= 1;
+ }
+
+ printf ("offset = %ld\n", offset);
+ fclose (fp);
+ }
+ }
+
+ return ret;
+}
+
+/* This test opens a file in append mode, writes some data, and then verifies
+ that ftell does not trip over it. */
+static int
+do_append_test (const char *filename)
+{
+ FILE *fp = NULL;
+ int ret = 0;
+ int fd;
+
+ struct test
+ {
+ const char *mode;
+ int fd_mode;
+ } test_modes[] = {
+ {"a", O_WRONLY},
+ {"a+", O_RDWR}
+ };
+
+ for (int j = 0; j < 2; j++)
+ {
+ for (int i = 0; i < sizeof (test_modes) / sizeof (struct test); i++)
+ {
+ printf ("\tappend: %s (file, \"%s\"): ", j == 0 ? "fopen" : "fdopen",
+ test_modes[i].mode);
+
+ if (j == 0)
+ ret = get_handles_fopen (filename, fd, fp, test_modes[i].mode);
+ else
+ ret = get_handles_fdopen (filename, fd, fp, test_modes[i].fd_mode,
+ test_modes[i].mode);
+
+ if (ret != 0)
+ return ret;
+
+ /* Write some data. */
+ size_t written = fputs_func (data, fp);
+
+ if (written == EOF)
+ {
+ printf ("fputs[1] failed to write all data\n");
+ ret |= 1;
+ }
+
+ /* Verify that the offset points to the end of the file. */
+ long offset = ftell (fp);
+ file_len += data_len;
+
+ if (offset != file_len)
+ {
+ printf ("Incorrect offset. Expected %zu, but got %ld\n",
+ file_len, offset);
+
+ ret |= 1;
+ }
+
+ printf ("offset = %ld\n", offset);
+ fclose (fp);
+ }
+ }
+
+ return ret;
+}
+
+static int
+do_one_test (const char *filename)
+{
+ int ret = 0;
+
+ ret |= do_ftell_test (filename);
+ ret |= do_write_test (filename);
+ ret |= do_append_test (filename);
+
+ return ret;
+}
+
+static int
+do_test (void)
+{
+ int ret = 0;
+ FILE *fp = NULL;
+ char *filename;
+ size_t written;
+ int fd = create_temp_file ("tst-active-handler-tmp.", &filename);
+
+ if (fd == -1)
+ {
+ printf ("create_temp_file: %m\n");
+ return 1;
+ }
+
+ fp = fdopen (fd, "w");
+ if (fp == NULL)
+ {
+ printf ("fdopen[0]: %m\n");
+ close (fd);
+ return 1;
+ }
+
+ data = char_data;
+ data_len = strlen (char_data);
+ file_len = strlen (char_data);
+ written = fputs (data, fp);
+
+ if (written == EOF)
+ {
+ printf ("fputs[1] failed to write data\n");
+ ret = 1;
+ }
+
+ fclose (fp);
+ if (ret)
+ return ret;
+
+ /* Tests for regular files. */
+ puts ("Regular mode:");
+ fputs_func = (fputs_func_t) fputs;
+ data = char_data;
+ data_len = strlen (char_data);
+ ret |= do_one_test (filename);
+
+ /* Truncate the file before repeating the tests in wide mode. */
+ fp = fopen (filename, "w");
+ if (fp == NULL)
+ {
+ printf ("fopen failed %m\n");
+ return 1;
+ }
+ fclose (fp);
+
+ /* Tests for wide files. */
+ puts ("Wide mode:");
+ if (setlocale (LC_ALL, "en_US.UTF-8") == NULL)
+ {
+ printf ("Cannot set en_US.UTF-8 locale.\n");
+ return 1;
+ }
+ fputs_func = (fputs_func_t) fputws;
+ data = wide_data;
+ data_len = wcslen (wide_data);
+ ret |= do_one_test (filename);
+
+ return ret;
+}
diff --git a/libio/wfileops.c b/libio/wfileops.c
index 9cebe77..eda7828 100644
--- a/libio/wfileops.c
+++ b/libio/wfileops.c
@@ -596,29 +596,22 @@ done:
return 0;
}
-_IO_off64_t
-_IO_wfile_seekoff (fp, offset, dir, mode)
- _IO_FILE *fp;
- _IO_off64_t offset;
- int dir;
- int mode;
+static _IO_off64_t
+do_ftell_wide (_IO_FILE *fp)
{
- _IO_off64_t result;
- _IO_off64_t delta, new_offset;
- long int count;
- /* POSIX.1 8.2.3.7 says that after a call the fflush() the file
- offset of the underlying file must be exact. */
- int must_be_exact = ((fp->_wide_data->_IO_read_base
- == fp->_wide_data->_IO_read_end)
- && (fp->_wide_data->_IO_write_base
- == fp->_wide_data->_IO_write_ptr));
+ _IO_off64_t result, offset = 0;
- bool was_writing = ((fp->_wide_data->_IO_write_ptr
- > fp->_wide_data->_IO_write_base)
- || _IO_in_put_mode (fp));
-
- if (mode == 0)
+ /* No point looking for offsets in the buffer if it hasn't even been
+ allocated. */
+ if (fp->_wide_data->_IO_buf_base != NULL)
{
+ const wchar_t *wide_read_base;
+ const wchar_t *wide_read_ptr;
+ const wchar_t *wide_read_end;
+ bool was_writing = ((fp->_wide_data->_IO_write_ptr
+ > fp->_wide_data->_IO_write_base)
+ || _IO_in_put_mode (fp));
+
/* XXX For wide stream with backup store it is not very
reasonable to determine the offset. The pushed-back
character might require a state change and we need not be
@@ -633,14 +626,117 @@ _IO_wfile_seekoff (fp, offset, dir, mode)
return -1;
}
- /* There is no more data in the backup buffer. We can
- switch back. */
- _IO_switch_to_main_wget_area (fp);
+ /* Nothing in the backup store, so note the backed up pointers
+ without changing the state. */
+ wide_read_base = fp->_wide_data->_IO_save_base;
+ wide_read_ptr = wide_read_base;
+ wide_read_end = fp->_wide_data->_IO_save_end;
+ }
+ else
+ {
+ wide_read_base = fp->_wide_data->_IO_read_base;
+ wide_read_ptr = fp->_wide_data->_IO_read_ptr;
+ wide_read_end = fp->_wide_data->_IO_read_end;
}
- dir = _IO_seek_cur, offset = 0; /* Don't move any pointers. */
+ struct _IO_codecvt *cv = fp->_codecvt;
+ int clen = (*cv->__codecvt_do_encoding) (cv);
+
+ if (!was_writing)
+ {
+ if (clen > 0)
+ {
+ offset -= (wide_read_end - wide_read_ptr) * clen;
+ offset -= fp->_IO_read_end - fp->_IO_read_ptr;
+ }
+ else
+ {
+ int nread;
+
+ size_t delta = wide_read_ptr - wide_read_base;
+ __mbstate_t state = fp->_wide_data->_IO_last_state;
+ nread = (*cv->__codecvt_do_length) (cv, &state,
+ fp->_IO_read_base,
+ fp->_IO_read_end, delta);
+ offset -= fp->_IO_read_end - fp->_IO_read_base - nread;
+ }
+ }
+ else
+ {
+ if (clen > 0)
+ offset += (fp->_wide_data->_IO_write_ptr
+ - fp->_wide_data->_IO_write_base) * clen;
+ else
+ {
+ size_t delta = (fp->_wide_data->_IO_write_ptr
+ - fp->_wide_data->_IO_write_base);
+
+ /* Allocate enough space for the conversion. */
+ size_t outsize = delta * sizeof (wchar_t);
+ char *out = malloc (outsize);
+ char *outstop = out;
+ const wchar_t *in = fp->_wide_data->_IO_write_base;
+
+ enum __codecvt_result status;
+
+ __mbstate_t state = fp->_wide_data->_IO_last_state;
+ status = (*cv->__codecvt_do_out) (cv, &state,
+ in, in + delta, &in,
+ out, out + outsize, &outstop);
+
+ /* We don't check for __codecvt_partial because it can be
+ returned on one of two conditions: either the output
+ buffer is full or the input sequence is incomplete. We
+ take care to allocate enough buffer and our input
+ sequences must be complete since they are accepted as
+ wchar_t; if not, then that is an error. */
+ if (__glibc_unlikely (status != __codecvt_ok))
+ return WEOF;
+
+ offset += outstop - out;
+ }
+
+ /* _IO_read_end coincides with fp._offset, so the actual file position
+ is fp._offset - (_IO_read_end - new_write_ptr). */
+ offset -= fp->_IO_read_end - fp->_IO_write_ptr;
+ }
}
+ result = get_file_offset (fp);
+
+ if (result == EOF)
+ return result;
+
+ result += offset;
+
+ return result;
+}
+
+_IO_off64_t
+_IO_wfile_seekoff (fp, offset, dir, mode)
+ _IO_FILE *fp;
+ _IO_off64_t offset;
+ int dir;
+ int mode;
+{
+ _IO_off64_t result;
+ _IO_off64_t delta, new_offset;
+ long int count;
+
+ if (mode == 0)
+ return do_ftell_wide (fp);
+
+ /* POSIX.1 8.2.3.7 says that after a call the fflush() the file
+ offset of the underlying file must be exact. */
+ int must_be_exact = ((fp->_wide_data->_IO_read_base
+ == fp->_wide_data->_IO_read_end)
+ && (fp->_wide_data->_IO_write_base
+ == fp->_wide_data->_IO_write_ptr));
+
+ bool was_writing = ((fp->_wide_data->_IO_write_ptr
+ > fp->_wide_data->_IO_write_base)
+ || _IO_in_put_mode (fp));
+
/* Flush unwritten characters.
(This may do an unneeded write if we seek within the buffer.
But to be able to switch to reading, we would need to set
@@ -648,7 +744,7 @@ _IO_wfile_seekoff (fp, offset, dir, mode)
which assumes file_ptr() is eGptr. Anyway, since we probably
end up flushing when we close(), it doesn't make much difference.)
FIXME: simulate mem-mapped files. */
- else if (was_writing && _IO_switch_to_wget_mode (fp))
+ if (was_writing && _IO_switch_to_wget_mode (fp))
return WEOF;
if (fp->_wide_data->_IO_buf_base == NULL)
@@ -693,7 +789,6 @@ _IO_wfile_seekoff (fp, offset, dir, mode)
{
int nread;
- flushed:
delta = (fp->_wide_data->_IO_read_ptr
- fp->_wide_data->_IO_read_base);
fp->_wide_data->_IO_state = fp->_wide_data->_IO_last_state;
@@ -706,80 +801,9 @@ _IO_wfile_seekoff (fp, offset, dir, mode)
offset -= fp->_IO_read_end - fp->_IO_read_base - nread;
}
}
- else
- {
- char *new_write_ptr = fp->_IO_write_ptr;
-
- if (clen > 0)
- offset += (fp->_wide_data->_IO_write_ptr
- - fp->_wide_data->_IO_write_base) / clen;
- else
- {
- enum __codecvt_result status = __codecvt_ok;
- delta = (fp->_wide_data->_IO_write_ptr
- - fp->_wide_data->_IO_write_base);
- const wchar_t *write_base = fp->_wide_data->_IO_write_base;
-
- /* FIXME: This actually ends up in two iterations of conversion,
- one here and the next when the buffer actually gets flushed.
- It may be possible to optimize this in future so that
- wdo_write identifies already converted content and does not
- redo it. In any case, this is much better than having to
- flush buffers for every ftell. */
- do
- {
- /* There is not enough space in the buffer to do the entire
- conversion, so there is no point trying to avoid the
- buffer flush. Just do it and go back to how it was with
- the read mode. */
- if (status == __codecvt_partial
- || (delta > 0 && new_write_ptr == fp->_IO_buf_end))
- {
- if (_IO_switch_to_wget_mode (fp))
- return WEOF;
- goto flushed;
- }
-
- const wchar_t *new_wbase = fp->_wide_data->_IO_write_base;
- fp->_wide_data->_IO_state = fp->_wide_data->_IO_last_state;
- status = (*cv->__codecvt_do_out) (cv,
- &fp->_wide_data->_IO_state,
- write_base,
- write_base + delta,
- &new_wbase,
- new_write_ptr,
- fp->_IO_buf_end,
- &new_write_ptr);
-
- delta -= new_wbase - write_base;
-
- /* If there was an error, then return WEOF.
- TODO: set buffer state. */
- if (__glibc_unlikely (status == __codecvt_error))
- return WEOF;
- }
- while (delta > 0);
- }
-
- /* _IO_read_end coincides with fp._offset, so the actual file position
- is fp._offset - (_IO_read_end - new_write_ptr). This is fine
- even if fp._offset is not set, since fp->_IO_read_end is then at
- _IO_buf_base and this adjustment is for unbuffered output. */
- offset -= fp->_IO_read_end - new_write_ptr;
- }
if (fp->_offset == _IO_pos_BAD)
- {
- if (mode != 0)
- goto dumb;
- else
- {
- result = _IO_SYSSEEK (fp, 0, dir);
- if (result == EOF)
- return result;
- fp->_offset = result;
- }
- }
+ goto dumb;
/* Make offset absolute, assuming current pointer is file_ptr(). */
offset += fp->_offset;
@@ -802,10 +826,6 @@ _IO_wfile_seekoff (fp, offset, dir, mode)
}
/* At this point, dir==_IO_seek_set. */
- /* If we are only interested in the current position we've found it now. */
- if (mode == 0)
- return offset;
-
/* If destination is within current buffer, optimize: */
if (fp->_offset != _IO_pos_BAD && fp->_IO_read_base != NULL
&& !_IO_in_backup (fp))

View File

@ -1,183 +0,0 @@
commit 4a68e8ded4fef2b00fbfc6baf1e79e46389871ca
Author: Siddhesh Poyarekar <siddhesh@redhat.com>
Date: Thu Feb 20 15:55:16 2014 +0530
Use cached offset in ftell when reliable
The cached offset is reliable to use in ftell when the stream handle
is active. We can consider a stream as being active when there is
unbuffered data. However, even in this case, we can use the cached
offset only when the stream is not being written to in a+ mode,
because this case may have unbuffered data and a stale offset; the
previous read could have sent it off somewhere other than the end of
the file.
There were a couple of adjustments necessary to get this to work.
Firstly, fdopen now ceases to use _IO_attach_fd because it sets the
offset cache to the current file position. This is not correct
because there could be changes to the file descriptor before the
stream handle is activated, which would not get reflected.
A similar offset caching action is done in _IO_fwide, claiming that
wide streams have 'problems' with the file offsets. There don't seem
to be any obvious problems with not having the offset cache available,
other than that it will have to be queried in a subsequent
read/write/seek. I have removed this as well.
The testsuite passes successfully with these changes on x86_64.
diff --git a/libio/fileops.c b/libio/fileops.c
index a177302..c44a5da 100644
--- a/libio/fileops.c
+++ b/libio/fileops.c
@@ -952,12 +952,8 @@ get_file_offset (_IO_FILE *fp)
static _IO_off64_t
do_ftell (_IO_FILE *fp)
{
- _IO_off64_t result;
-
- result = get_file_offset (fp);
-
- if (result == EOF)
- return result;
+ _IO_off64_t result = 0;
+ bool use_cached_offset = false;
/* No point looking at unflushed data if we haven't allocated buffers
yet. */
@@ -971,8 +967,34 @@ do_ftell (_IO_FILE *fp)
result -= fp->_IO_read_end - fp->_IO_read_ptr;
else
result += fp->_IO_write_ptr - fp->_IO_read_end;
+
+ /* It is safe to use the cached offset when available if there is
+ unbuffered data (indicating that the file handle is active) and the
+ handle is not for a file open in a+ mode. The latter condition is
+ because there could be a scenario where there is a switch from read
+ mode to write mode using an fseek to an arbitrary position. In this
+ case, there would be unbuffered data due to be appended to the end of
+ the file, but the offset may not necessarily be the end of the
+ file. It is fine to use the cached offset when the a+ stream is in
+ read mode though, since the offset is maintained correctly in that
+ case. Note that this is not a comprehensive set of cases when the
+ offset is reliable. The offset may be reliable even in some cases
+ where there is no buffered input and the handle is active, but it's
+ just that we don't have a way to identify that condition reliably. */
+ use_cached_offset = (result != 0 && fp->_offset != _IO_pos_BAD
+ && ((fp->_flags & (_IO_IS_APPENDING | _IO_NO_READS))
+ == (_IO_IS_APPENDING | _IO_NO_READS)
+ && was_writing));
}
+ if (use_cached_offset)
+ result += fp->_offset;
+ else
+ result += get_file_offset (fp);
+
+ if (result == EOF)
+ return result;
+
if (result < 0)
{
__set_errno (EINVAL);
diff --git a/libio/iofdopen.c b/libio/iofdopen.c
index 066ff19..4525f0f 100644
--- a/libio/iofdopen.c
+++ b/libio/iofdopen.c
@@ -141,9 +141,6 @@ _IO_new_fdopen (fd, mode)
#ifdef _IO_MTSAFE_IO
new_f->fp.file._lock = &new_f->lock;
#endif
- /* Set up initially to use the `maybe_mmap' jump tables rather than using
- __fopen_maybe_mmap to do it, because we need them in place before we
- call _IO_file_attach or else it will allocate a buffer immediately. */
_IO_no_init (&new_f->fp.file, 0, 0, &new_f->wd,
#ifdef _G_HAVE_MMAP
(use_mmap && (read_write & _IO_NO_WRITES))
@@ -159,13 +156,10 @@ _IO_new_fdopen (fd, mode)
#if !_IO_UNIFIED_JUMPTABLES
new_f->fp.vtable = NULL;
#endif
- if (_IO_file_attach ((_IO_FILE *) &new_f->fp, fd) == NULL)
- {
- _IO_setb (&new_f->fp.file, NULL, NULL, 0);
- _IO_un_link (&new_f->fp);
- free (new_f);
- return NULL;
- }
+ /* We only record the fd because _IO_file_init will have unset the offset.
+ We don't need to get the current offset in the file now since it could
+ change between now and when the handle is activated. */
+ new_f->fp.file._fileno = fd;
new_f->fp.file._flags &= ~_IO_DELETE_DONT_CLOSE;
_IO_mask_flags (&new_f->fp.file, read_write,
diff --git a/libio/iofwide.c b/libio/iofwide.c
index 5cff632..64187e4 100644
--- a/libio/iofwide.c
+++ b/libio/iofwide.c
@@ -199,12 +199,6 @@ _IO_fwide (fp, mode)
/* From now on use the wide character callback functions. */
((struct _IO_FILE_plus *) fp)->vtable = fp->_wide_data->_wide_vtable;
-
- /* One last twist: we get the current stream position. The wide
- char streams have much more problems with not knowing the
- current position and so we should disable the optimization
- which allows the functions without knowing the position. */
- fp->_offset = _IO_SYSSEEK (fp, 0, _IO_seek_cur);
}
/* Set the mode now. */
diff --git a/libio/wfileops.c b/libio/wfileops.c
index eda7828..651f5ce 100644
--- a/libio/wfileops.c
+++ b/libio/wfileops.c
@@ -600,6 +600,7 @@ static _IO_off64_t
do_ftell_wide (_IO_FILE *fp)
{
_IO_off64_t result, offset = 0;
+ bool use_cached_offset = false;
/* No point looking for offsets in the buffer if it hasn't even been
allocated. */
@@ -696,13 +697,36 @@ do_ftell_wide (_IO_FILE *fp)
offset += outstop - out;
}
- /* _IO_read_end coincides with fp._offset, so the actual file position
- is fp._offset - (_IO_read_end - new_write_ptr). */
+ /* _IO_read_end coincides with fp._offset, so the actual file
+ position is fp._offset - (_IO_read_end - new_write_ptr). */
offset -= fp->_IO_read_end - fp->_IO_write_ptr;
+
}
+
+ /* It is safe to use the cached offset when available if there is
+ unbuffered data (indicating that the file handle is active) and
+ the handle is not for a file open in a+ mode. The latter
+ condition is because there could be a scenario where there is a
+ switch from read mode to write mode using an fseek to an arbitrary
+ position. In this case, there would be unbuffered data due to be
+ appended to the end of the file, but the offset may not
+ necessarily be the end of the file. It is fine to use the cached
+ offset when the a+ stream is in read mode though, since the offset
+ is maintained correctly in that case. Note that this is not a
+ comprehensive set of cases when the offset is reliable. The
+ offset may be reliable even in some cases where there is no
+ buffered input and the handle is active, but it's just that we
+ don't have a way to identify that condition reliably. */
+ use_cached_offset = (offset != 0 && fp->_offset != _IO_pos_BAD
+ && ((fp->_flags & (_IO_IS_APPENDING | _IO_NO_READS))
+ == (_IO_IS_APPENDING | _IO_NO_READS)
+ && was_writing));
}
- result = get_file_offset (fp);
+ if (use_cached_offset)
+ result = fp->_offset;
+ else
+ result = get_file_offset (fp);
if (result == EOF)
return result;

View File

@ -1,393 +0,0 @@
Revert this upstream commit:
commit 2212c1420c92a33b0e0bd9a34938c9814a56c0f7
Author: Andreas Schwab <schwab@suse.de>
Date: Thu Feb 19 15:52:08 2015 +0100
Simplify handling of nameserver configuration in resolver
Remove use of ext.nsmap member of struct __res_state and always use
an identity mapping betwen the nsaddr_list array and the ext.nsaddrs
array. The fact that a nameserver has an IPv6 address is signalled by
setting nsaddr_list[].sin_family to zero.
reverted:
Index: glibc-2.23-276-gb65b205/resolv/res_init.c
===================================================================
--- glibc-2.23-276-gb65b205.orig/resolv/res_init.c
+++ glibc-2.23-276-gb65b205/resolv/res_init.c
@@ -122,8 +122,8 @@ __res_vinit(res_state statp, int preinit
char *cp, **pp;
int n;
char buf[BUFSIZ];
- int nserv = 0; /* number of nameservers read from file */
- int have_serv6 = 0;
+ int nserv = 0; /* number of IPv4 nameservers read from file */
+ int nservall = 0; /* number of (IPv4 + IPV6) nameservers read from file */
int haveenv = 0;
int havesearch = 0;
int nsort = 0;
@@ -145,9 +145,15 @@ __res_vinit(res_state statp, int preinit
statp->_flags = 0;
statp->qhook = NULL;
statp->rhook = NULL;
+ statp->_u._ext.nsinit = 0;
statp->_u._ext.nscount = 0;
- for (n = 0; n < MAXNS; n++)
- statp->_u._ext.nsaddrs[n] = NULL;
+#ifdef _LIBC
+ statp->_u._ext.nscount6 = 0;
+ for (n = 0; n < MAXNS; n++) {
+ statp->_u._ext.nsaddrs[n] = NULL;
+ statp->_u._ext.nsmap[n] = MAXNS;
+ }
+#endif
/* Allow user to override the local domain definition */
if ((cp = getenv("LOCALDOMAIN")) != NULL) {
@@ -251,7 +257,11 @@ __res_vinit(res_state statp, int preinit
continue;
}
/* read nameservers to query */
+#ifdef _LIBC
+ if (MATCH(buf, "nameserver") && nservall < MAXNS) {
+#else
if (MATCH(buf, "nameserver") && nserv < MAXNS) {
+#endif
struct in_addr a;
cp = buf + sizeof("nameserver") - 1;
@@ -259,11 +269,12 @@ __res_vinit(res_state statp, int preinit
cp++;
if ((*cp != '\0') && (*cp != '\n')
&& __inet_aton(cp, &a)) {
- statp->nsaddr_list[nserv].sin_addr = a;
- statp->nsaddr_list[nserv].sin_family = AF_INET;
- statp->nsaddr_list[nserv].sin_port =
+ statp->nsaddr_list[nservall].sin_addr = a;
+ statp->nsaddr_list[nservall].sin_family = AF_INET;
+ statp->nsaddr_list[nservall].sin_port =
htons(NAMESERVER_PORT);
nserv++;
+ nservall++;
} else {
struct in6_addr a6;
char *el;
@@ -305,11 +316,10 @@ __res_vinit(res_state statp, int preinit
}
}
- statp->nsaddr_list[nserv].sin_family = 0;
- statp->_u._ext.nsaddrs[nserv] = sa6;
- statp->_u._ext.nssocks[nserv] = -1;
- have_serv6 = 1;
- nserv++;
+ statp->_u._ext.nsaddrs[nservall] = sa6;
+ statp->_u._ext.nssocks[nservall] = -1;
+ statp->_u._ext.nsmap[nservall] = MAXNS + 1;
+ nservall++;
}
}
}
@@ -361,8 +371,9 @@ __res_vinit(res_state statp, int preinit
continue;
}
}
- statp->nscount = nserv;
- if (have_serv6) {
+ statp->nscount = nservall;
+ if (nservall - nserv > 0) {
+ statp->_u._ext.nscount6 = nservall - nserv;
/* We try IPv6 servers again. */
statp->ipv6_unavail = false;
}
@@ -532,6 +543,8 @@ __res_iclose(res_state statp, bool free_
statp->_u._ext.nsaddrs[ns] = NULL;
}
}
+ if (free_addr)
+ statp->_u._ext.nsinit = 0;
}
libc_hidden_def (__res_iclose)
Index: glibc-2.23-276-gb65b205/resolv/res_send.c
===================================================================
--- glibc-2.23-276-gb65b205.orig/resolv/res_send.c
+++ glibc-2.23-276-gb65b205/resolv/res_send.c
@@ -188,7 +188,6 @@ evNowTime(struct timespec *res) {
/* Forward. */
-static struct sockaddr *get_nsaddr (res_state, int);
static int send_vc(res_state, const u_char *, int,
const u_char *, int,
u_char **, int *, int *, int, u_char **,
@@ -226,21 +225,20 @@ res_ourserver_p(const res_state statp, c
in_port_t port = in4p->sin_port;
in_addr_t addr = in4p->sin_addr.s_addr;
- for (ns = 0; ns < statp->nscount; ns++) {
+ for (ns = 0; ns < MAXNS; ns++) {
const struct sockaddr_in *srv =
- (struct sockaddr_in *) get_nsaddr (statp, ns);
+ (struct sockaddr_in *)EXT(statp).nsaddrs[ns];
- if ((srv->sin_family == AF_INET) &&
+ if ((srv != NULL) && (srv->sin_family == AF_INET) &&
(srv->sin_port == port) &&
(srv->sin_addr.s_addr == INADDR_ANY ||
srv->sin_addr.s_addr == addr))
return (1);
}
} else if (inp->sin6_family == AF_INET6) {
- for (ns = 0; ns < statp->nscount; ns++) {
- const struct sockaddr_in6 *srv
- = (struct sockaddr_in6 *) get_nsaddr (statp, ns);
- if ((srv->sin6_family == AF_INET6) &&
+ for (ns = 0; ns < MAXNS; ns++) {
+ const struct sockaddr_in6 *srv = EXT(statp).nsaddrs[ns];
+ if ((srv != NULL) && (srv->sin6_family == AF_INET6) &&
(srv->sin6_port == inp->sin6_port) &&
!(memcmp(&srv->sin6_addr, &in6addr_any,
sizeof (struct in6_addr)) &&
@@ -392,48 +390,80 @@ __libc_res_nsend(res_state statp, const
* If the ns_addr_list in the resolver context has changed, then
* invalidate our cached copy and the associated timing data.
*/
- if (EXT(statp).nscount != 0) {
+ if (EXT(statp).nsinit) {
int needclose = 0;
if (EXT(statp).nscount != statp->nscount)
needclose++;
else
- for (ns = 0; ns < statp->nscount; ns++) {
- if (statp->nsaddr_list[ns].sin_family != 0
+ for (ns = 0; ns < MAXNS; ns++) {
+ unsigned int map = EXT(statp).nsmap[ns];
+ if (map < MAXNS
&& !sock_eq((struct sockaddr_in6 *)
- &statp->nsaddr_list[ns],
+ &statp->nsaddr_list[map],
EXT(statp).nsaddrs[ns]))
{
needclose++;
break;
}
}
- if (needclose) {
+ if (needclose)
__res_iclose(statp, false);
- EXT(statp).nscount = 0;
- }
}
/*
* Maybe initialize our private copy of the ns_addr_list.
*/
- if (EXT(statp).nscount == 0) {
- for (ns = 0; ns < statp->nscount; ns++) {
- EXT(statp).nssocks[ns] = -1;
- if (statp->nsaddr_list[ns].sin_family == 0)
- continue;
- if (EXT(statp).nsaddrs[ns] == NULL)
- EXT(statp).nsaddrs[ns] =
+ if (EXT(statp).nsinit == 0) {
+ unsigned char map[MAXNS];
+
+ memset (map, MAXNS, sizeof (map));
+ for (n = 0; n < MAXNS; n++) {
+ ns = EXT(statp).nsmap[n];
+ if (ns < statp->nscount)
+ map[ns] = n;
+ else if (ns < MAXNS) {
+ free(EXT(statp).nsaddrs[n]);
+ EXT(statp).nsaddrs[n] = NULL;
+ EXT(statp).nsmap[n] = MAXNS;
+ }
+ }
+ n = statp->nscount;
+ if (statp->nscount > EXT(statp).nscount)
+ for (n = EXT(statp).nscount, ns = 0;
+ n < statp->nscount; n++) {
+ while (ns < MAXNS
+ && EXT(statp).nsmap[ns] != MAXNS)
+ ns++;
+ if (ns == MAXNS)
+ break;
+ /* NS never exceeds MAXNS, but gcc 4.9 somehow
+ does not see this. */
+ DIAG_PUSH_NEEDS_COMMENT;
+ DIAG_IGNORE_NEEDS_COMMENT (4.9,
+ "-Warray-bounds");
+ EXT(statp).nsmap[ns] = n;
+ DIAG_POP_NEEDS_COMMENT;
+ map[n] = ns++;
+ }
+ EXT(statp).nscount = n;
+ for (ns = 0; ns < EXT(statp).nscount; ns++) {
+ n = map[ns];
+ if (EXT(statp).nsaddrs[n] == NULL)
+ EXT(statp).nsaddrs[n] =
malloc(sizeof (struct sockaddr_in6));
- if (EXT(statp).nsaddrs[ns] != NULL)
- memset (mempcpy(EXT(statp).nsaddrs[ns],
+ if (EXT(statp).nsaddrs[n] != NULL) {
+ memset (mempcpy(EXT(statp).nsaddrs[n],
&statp->nsaddr_list[ns],
sizeof (struct sockaddr_in)),
'\0',
sizeof (struct sockaddr_in6)
- sizeof (struct sockaddr_in));
+ EXT(statp).nssocks[n] = -1;
+ n++;
+ }
}
- EXT(statp).nscount = statp->nscount;
+ EXT(statp).nsinit = 1;
}
/*
@@ -442,37 +472,44 @@ __libc_res_nsend(res_state statp, const
*/
if (__builtin_expect ((statp->options & RES_ROTATE) != 0, 0) &&
(statp->options & RES_BLAST) == 0) {
- struct sockaddr_in ina;
- struct sockaddr_in6 *inp;
- int lastns = statp->nscount - 1;
- int fd;
-
- inp = EXT(statp).nsaddrs[0];
- ina = statp->nsaddr_list[0];
- fd = EXT(statp).nssocks[0];
- for (ns = 0; ns < lastns; ns++) {
- EXT(statp).nsaddrs[ns] = EXT(statp).nsaddrs[ns + 1];
- statp->nsaddr_list[ns] = statp->nsaddr_list[ns + 1];
- EXT(statp).nssocks[ns] = EXT(statp).nssocks[ns + 1];
- }
- EXT(statp).nsaddrs[lastns] = inp;
- statp->nsaddr_list[lastns] = ina;
- EXT(statp).nssocks[lastns] = fd;
+ struct sockaddr_in6 *ina;
+ unsigned int map;
+
+ n = 0;
+ while (n < MAXNS && EXT(statp).nsmap[n] == MAXNS)
+ n++;
+ if (n < MAXNS) {
+ ina = EXT(statp).nsaddrs[n];
+ map = EXT(statp).nsmap[n];
+ for (;;) {
+ ns = n + 1;
+ while (ns < MAXNS
+ && EXT(statp).nsmap[ns] == MAXNS)
+ ns++;
+ if (ns == MAXNS)
+ break;
+ EXT(statp).nsaddrs[n] = EXT(statp).nsaddrs[ns];
+ EXT(statp).nsmap[n] = EXT(statp).nsmap[ns];
+ n = ns;
+ }
+ EXT(statp).nsaddrs[n] = ina;
+ EXT(statp).nsmap[n] = map;
+ }
}
/*
* Send request, RETRY times, or until successful.
*/
for (try = 0; try < statp->retry; try++) {
- for (ns = 0; ns < statp->nscount; ns++)
+ for (ns = 0; ns < MAXNS; ns++)
{
#ifdef DEBUG
char tmpbuf[40];
#endif
-#if defined USE_HOOKS || defined DEBUG
- struct sockaddr *nsap = get_nsaddr (statp, ns);
-#endif
+ struct sockaddr_in6 *nsap = EXT(statp).nsaddrs[ns];
+ if (nsap == NULL)
+ goto next_ns;
same_ns:
#ifdef USE_HOOKS
if (__glibc_unlikely (statp->qhook != NULL)) {
@@ -629,21 +666,6 @@ libresolv_hidden_def (res_nsend)
/* Private */
-static struct sockaddr *
-get_nsaddr (res_state statp, int n)
-{
-
- if (statp->nsaddr_list[n].sin_family == 0 && EXT(statp).nsaddrs[n] != NULL)
- /* EXT(statp).nsaddrs[n] holds an address that is larger than
- struct sockaddr, and user code did not update
- statp->nsaddr_list[n]. */
- return (struct sockaddr *) EXT(statp).nsaddrs[n];
- else
- /* User code updated statp->nsaddr_list[n], or statp->nsaddr_list[n]
- has the same content as EXT(statp).nsaddrs[n]. */
- return (struct sockaddr *) (void *) &statp->nsaddr_list[n];
-}
-
/* Close the resolver structure, assign zero to *RESPLEN2 if RESPLEN2
is not NULL, and return zero. */
static int
@@ -737,7 +759,7 @@ send_vc(res_state statp,
const HEADER *hp = (HEADER *) buf;
const HEADER *hp2 = (HEADER *) buf2;
HEADER *anhp = (HEADER *) *ansp;
- struct sockaddr *nsap = get_nsaddr (statp, ns);
+ struct sockaddr_in6 *nsap = EXT(statp).nsaddrs[ns];
int truncating, connreset, n;
/* On some architectures compiler might emit a warning indicating
'resplen' may be used uninitialized. However if buf2 == NULL
@@ -768,8 +790,8 @@ send_vc(res_state statp,
if (getpeername(statp->_vcsock,
(struct sockaddr *)&peer, &size) < 0 ||
- !sock_eq(&peer, (struct sockaddr_in6 *) nsap)) {
- __res_iclose(statp, false);
+ !sock_eq(&peer, nsap)) {
+ __res_iclose(statp, false);
statp->_flags &= ~RES_F_VC;
}
}
@@ -778,7 +800,7 @@ send_vc(res_state statp,
if (statp->_vcsock >= 0)
__res_iclose(statp, false);
- statp->_vcsock = socket(nsap->sa_family, SOCK_STREAM, 0);
+ statp->_vcsock = socket(nsap->sin6_family, SOCK_STREAM, 0);
if (statp->_vcsock < 0) {
*terrno = errno;
Perror(statp, stderr, "socket(vc)", errno);
@@ -787,12 +809,13 @@ send_vc(res_state statp,
return (-1);
}
__set_errno (0);
- if (connect(statp->_vcsock, nsap,
- nsap->sa_family == AF_INET
+ if (connect(statp->_vcsock, (struct sockaddr *)nsap,
+ nsap->sin6_family == AF_INET
? sizeof (struct sockaddr_in)
: sizeof (struct sockaddr_in6)) < 0) {
*terrno = errno;
- Aerror(statp, stderr, "connect/vc", errno, nsap);
+ Aerror(statp, stderr, "connect/vc", errno,
+ (struct sockaddr *) nsap);
return close_and_return_error (statp, resplen2);
}
statp->_flags |= RES_F_VC;
@@ -983,7 +1006,8 @@ static int
reopen (res_state statp, int *terrno, int ns)
{
if (EXT(statp).nssocks[ns] == -1) {
- struct sockaddr *nsap = get_nsaddr (statp, ns);
+ struct sockaddr *nsap
+ = (struct sockaddr *) EXT(statp).nsaddrs[ns];
socklen_t slen;
/* only try IPv6 if IPv6 NS and if not failed before */

View File

@ -1,11 +0,0 @@
Short description: <Short description>
Author(s): <Who wrote them. Comma separated.>
Origin: <Source repo(s) where it came from or keyword "PATCH" if this is simply a patch>
# Likely git://sourceware.org/git/glibc.git
Bug-RHEL: <Rhel bug #'s, comma separated e.g. #XXX, #YYY, #ZZZ>
Bug-Fedora: <Fedora bug #'s, comma separated e.g. #XXX, #YYY, #ZZZ>
Bug-Upstream: <Upstream bug#'s, comma separated e.g. #XXX, #YYY, #ZZZ>
Upstream status: <[Patchwork URL|not-needed|not-submitted|committed] for each commit>
# <Additional descriptive text in comment block>
<If upstream status == committed then a copy of the upstream commit log follows>
<Patch>