Commit 2486c24a by Richard Biener Committed by Richard Biener

simple-object.c (simple_object_internal_read): Handle EINTR and short reads.

2014-03-28  Richard Biener  <rguenther@suse.de>

	libiberty/
	* simple-object.c (simple_object_internal_read): Handle
	EINTR and short reads.

	lto-plugin/
	* lto-plugin.c (process_symtab): Handle EINTR and short reads.

From-SVN: r208898
parent 44d62789
2014-03-28 Richard Biener <rguenther@suse.de>
* simple-object.c (simple_object_internal_read): Handle
EINTR and short reads.
2014-03-13 Uros Bizjak <ubizjak@gmail.com> 2014-03-13 Uros Bizjak <ubizjak@gmail.com>
* regex.c (bzero) [!_LIBC]: Define without coma expression. * regex.c (bzero) [!_LIBC]: Define without coma expression.
......
...@@ -63,8 +63,6 @@ simple_object_internal_read (int descriptor, off_t offset, ...@@ -63,8 +63,6 @@ simple_object_internal_read (int descriptor, off_t offset,
unsigned char *buffer, size_t size, unsigned char *buffer, size_t size,
const char **errmsg, int *err) const char **errmsg, int *err)
{ {
ssize_t got;
if (lseek (descriptor, offset, SEEK_SET) < 0) if (lseek (descriptor, offset, SEEK_SET) < 0)
{ {
*errmsg = "lseek"; *errmsg = "lseek";
...@@ -72,15 +70,26 @@ simple_object_internal_read (int descriptor, off_t offset, ...@@ -72,15 +70,26 @@ simple_object_internal_read (int descriptor, off_t offset,
return 0; return 0;
} }
got = read (descriptor, buffer, size); do
if (got < 0)
{ {
*errmsg = "read"; ssize_t got = read (descriptor, buffer, size);
*err = errno; if (got == 0)
return 0; break;
else if (got > 0)
{
buffer += got;
size -= got;
}
else if (errno != EINTR)
{
*errmsg = "read";
*err = errno;
return 0;
}
} }
while (size > 0);
if ((size_t) got < size) if (size > 0)
{ {
*errmsg = "file too short"; *errmsg = "file too short";
*err = 0; *err = 0;
......
2014-03-28 Richard Biener <rguenther@suse.de>
* lto-plugin.c (process_symtab): Handle EINTR and short reads.
2014-03-17 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> 2014-03-17 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
* configure.ac (ac_lto_plugin_ldflags): Set to -Wc,-static-libgcc * configure.ac (ac_lto_plugin_ldflags): Set to -Wc,-static-libgcc
......
...@@ -39,6 +39,7 @@ along with this program; see the file COPYING3. If not see ...@@ -39,6 +39,7 @@ along with this program; see the file COPYING3. If not see
#include <stdint.h> #include <stdint.h>
#endif #endif
#include <assert.h> #include <assert.h>
#include <errno.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
...@@ -817,7 +818,7 @@ process_symtab (void *data, const char *name, off_t offset, off_t length) ...@@ -817,7 +818,7 @@ process_symtab (void *data, const char *name, off_t offset, off_t length)
{ {
struct plugin_objfile *obj = (struct plugin_objfile *)data; struct plugin_objfile *obj = (struct plugin_objfile *)data;
char *s; char *s;
char *secdata; char *secdatastart, *secdata;
if (strncmp (name, LTO_SECTION_PREFIX, LTO_SECTION_PREFIX_LEN) != 0) if (strncmp (name, LTO_SECTION_PREFIX, LTO_SECTION_PREFIX_LEN) != 0)
return 1; return 1;
...@@ -825,23 +826,40 @@ process_symtab (void *data, const char *name, off_t offset, off_t length) ...@@ -825,23 +826,40 @@ process_symtab (void *data, const char *name, off_t offset, off_t length)
s = strrchr (name, '.'); s = strrchr (name, '.');
if (s) if (s)
sscanf (s, ".%" PRI_LL "x", &obj->out->id); sscanf (s, ".%" PRI_LL "x", &obj->out->id);
secdata = xmalloc (length); secdata = secdatastart = xmalloc (length);
offset += obj->file->offset; offset += obj->file->offset;
if (offset != lseek (obj->file->fd, offset, SEEK_SET) if (offset != lseek (obj->file->fd, offset, SEEK_SET))
|| length != read (obj->file->fd, secdata, length)) goto err;
do
{ {
if (message) ssize_t got = read (obj->file->fd, secdata, length);
message (LDPL_FATAL, "%s: corrupt object file", obj->file->name); if (got == 0)
/* Force claim_file_handler to abandon this file. */ break;
obj->found = 0; else if (got > 0)
free (secdata); {
return 0; secdata += got;
length -= got;
}
else if (errno != EINTR)
goto err;
} }
while (length > 0);
if (length > 0)
goto err;
translate (secdata, secdata + length, obj->out); translate (secdatastart, secdata, obj->out);
obj->found++; obj->found++;
free (secdata); free (secdatastart);
return 1; return 1;
err:
if (message)
message (LDPL_FATAL, "%s: corrupt object file", obj->file->name);
/* Force claim_file_handler to abandon this file. */
obj->found = 0;
free (secdatastart);
return 0;
} }
/* Callback used by gold to check if the plugin will claim FILE. Writes /* Callback used by gold to check if the plugin will claim FILE. Writes
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment