+2014-12-11 20:01 Christos Zoulas <christos@zoulas.com>
+
+ * PR/405: ignore SIGPIPE from uncompress programs
+ * change printable -> file_printable and use it in
+ more places for safety
+ * in ELF, instead of "(uses dynamic libraries)" when PT_INTERP
+ is present print the interpreter name.
+
2014-12-10 20:01 Christos Zoulas <christos@zoulas.com>
* release 5.21
*/
/*
* file.h - definitions for file(1) program
- * @(#)$File: file.h,v 1.161 2014/12/04 15:56:46 christos Exp $
+ * @(#)$File: file.h,v 1.162 2014/12/11 12:34:24 christos Exp $
*/
#ifndef __file_h__
size_t *);
protected size_t file_pstring_length_size(const struct magic *);
protected size_t file_pstring_get_length(const struct magic *, const char *);
+protected char * file_printable(char *, size_t, const char *);
#ifdef __EMX__
protected int file_os2_apptype(struct magic_set *, const char *, const void *,
size_t);
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: funcs.c,v 1.77 2014/11/28 02:46:39 christos Exp $")
+FILE_RCSID("@(#)$File: funcs.c,v 1.78 2014/12/11 12:34:24 christos Exp $")
#endif /* lint */
#include "magic.h"
free(pb);
return rbuf;
}
+
+/*
+ * convert string to ascii printable format.
+ */
+protected char *
+file_printable(char *buf, size_t bufsiz, const char *str)
+{
+ char *ptr, *eptr;
+ const unsigned char *s = (const unsigned char *)str;
+
+ for (ptr = buf, eptr = ptr + bufsiz - 1; ptr < eptr && *s; s++) {
+ if (isprint(*s)) {
+ *ptr++ = *s;
+ continue;
+ }
+ if (ptr >= eptr + 4)
+ break;
+ *ptr++ = '\\';
+ *ptr++ = ((*s >> 6) & 7) + '0';
+ *ptr++ = ((*s >> 3) & 7) + '0';
+ *ptr++ = ((*s >> 0) & 7) + '0';
+ }
+ *ptr = '\0';
+ return buf;
+}
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: readelf.c,v 1.111 2014/12/09 02:47:45 christos Exp $")
+FILE_RCSID("@(#)$File: readelf.c,v 1.112 2014/12/11 12:34:24 christos Exp $")
#endif
#ifdef BUILTIN_ELF
#endif
uint32_t namesz, descsz;
unsigned char *nbuf = CAST(unsigned char *, vbuf);
+ char sbuf[512];
if (xnh_sizeof + offset > size) {
/*
* including the terminating NUL.
*/
if (file_printf(ms, ", from '%.31s'",
- &nbuf[doff + 0x7c]) == -1)
+ file_printable(sbuf, sizeof(sbuf),
+ (const char *)&nbuf[doff + 0x7c])) == -1)
return size;
/*
Elf32_Phdr ph32;
Elf64_Phdr ph64;
const char *linking_style = "statically";
- const char *shared_libraries = "";
+ const char *interp = "";
unsigned char nbuf[BUFSIZ];
+ char ibuf[BUFSIZ];
ssize_t bufsize;
size_t offset, align, len;
}
off += size;
+ bufsize = 0;
+ align = 4;
/* Things we can determine before we seek */
switch (xph_type) {
case PT_DYNAMIC:
linking_style = "dynamically";
break;
+ case PT_NOTE:
+ if (sh_num) /* Did this through section headers */
+ continue;
+ if (((align = xph_align) & 0x80000000UL) != 0 ||
+ align < 4) {
+ if (file_printf(ms,
+ ", invalid note alignment 0x%lx",
+ (unsigned long)align) == -1)
+ return -1;
+ align = 4;
+ }
+ /*FALLTHROUGH*/
case PT_INTERP:
- shared_libraries = " (uses shared libs)";
+ len = xph_filesz < sizeof(nbuf) ? xph_filesz
+ : sizeof(nbuf);
+ bufsize = pread(fd, nbuf, len, xph_offset);
+ if (bufsize == -1) {
+ file_badread(ms);
+ return -1;
+ }
break;
default:
if (fsize != SIZE_UNKNOWN && xph_offset > fsize) {
/* Things we can determine when we seek */
switch (xph_type) {
- case PT_NOTE:
- if (((align = xph_align) & 0x80000000UL) != 0 ||
- align < 4) {
- if (file_printf(ms,
- ", invalid note alignment 0x%lx",
- (unsigned long)align) == -1)
- return -1;
- align = 4;
+ case PT_INTERP:
+ if (bufsize) {
+ nbuf[bufsize - 1] = '\0';
+ interp = (const char *)nbuf;
}
- if (sh_num)
- break;
+ break;
+ case PT_NOTE:
/*
* This is a PT_NOTE section; loop through all the notes
* in the section.
*/
- len = xph_filesz < sizeof(nbuf) ? xph_filesz
- : sizeof(nbuf);
- bufsize = pread(fd, nbuf, len, xph_offset);
- if (bufsize == -1) {
- file_badread(ms);
- return -1;
- }
offset = 0;
for (;;) {
if (offset >= (size_t)bufsize)
break;
}
}
- if (file_printf(ms, ", %s linked%s", linking_style, shared_libraries)
+ if (file_printf(ms, ", %s linked", linking_style)
== -1)
- return -1;
+ return -1;
+ if (interp[0])
+ if (file_printf(ms, ", interpreter %s",
+ file_printable(ibuf, sizeof(ibuf), interp)) == -1)
+ return -1;
return 0;
}
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: softmagic.c,v 1.203 2014/12/04 15:22:05 christos Exp $")
+FILE_RCSID("@(#)$File: softmagic.c,v 1.204 2014/12/11 12:34:24 christos Exp $")
#endif /* lint */
#include "magic.h"
}
#endif /* HAVE_STRNDUP */
-static char *
-printable(char *buf, size_t bufsiz, const char *str)
-{
- char *ptr, *eptr;
- const unsigned char *s = (const unsigned char *)str;
-
- for (ptr = buf, eptr = ptr + bufsiz - 1; ptr < eptr && *s; s++) {
- if (isprint(*s)) {
- *ptr++ = *s;
- continue;
- }
- if (ptr >= eptr + 4)
- break;
- *ptr++ = '\\';
- *ptr++ = ((*s >> 6) & 7) + '0';
- *ptr++ = ((*s >> 3) & 7) + '0';
- *ptr++ = ((*s >> 0) & 7) + '0';
- }
- *ptr = '\0';
- return buf;
-}
-
private int32_t
mprint(struct magic_set *ms, struct magic *m)
{
float vf;
double vd;
int64_t t = 0;
- char buf[128], tbuf[26];
+ char buf[128], tbuf[26], sbuf[512];
union VALUETYPE *p = &ms->ms_value;
switch (m->type) {
case FILE_BESTRING16:
case FILE_LESTRING16:
if (m->reln == '=' || m->reln == '!') {
- if (file_printf(ms, F(ms, m, "%s"), m->value.s) == -1)
+ if (file_printf(ms, F(ms, m, "%s"),
+ file_printable(sbuf, sizeof(sbuf), m->value.s))
+ == -1)
return -1;
t = ms->offset + m->vallen;
}
else {
- char sbuf[512];
char *str = p->s;
/* compute t before we mangle the string? */
}
if (file_printf(ms, F(ms, m, "%s"),
- printable(sbuf, sizeof(sbuf), str)) == -1)
+ file_printable(sbuf, sizeof(sbuf), str)) == -1)
return -1;
if (m->type == FILE_PSTRING)
file_oomem(ms, ms->search.rm_len);
return -1;
}
- rval = file_printf(ms, F(ms, m, "%s"), cp);
+ rval = file_printf(ms, F(ms, m, "%s"),
+ file_printable(sbuf, sizeof(sbuf), cp));
free(cp);
if (rval == -1)
}
case FILE_SEARCH:
- if (file_printf(ms, F(ms, m, "%s"), m->value.s) == -1)
+ if (file_printf(ms, F(ms, m, "%s"),
+ file_printable(sbuf, sizeof(sbuf), m->value.s)) == -1)
return -1;
if ((m->str_flags & REGEX_OFFSET_START))
t = ms->search.offset;