summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristos Zoulas <christos@zoulas.com>2006-10-27 14:57:32 +0000
committerChristos Zoulas <christos@zoulas.com>2006-10-27 14:57:32 +0000
commita01c49e324e31dbd62d54b46c1141b70de53d810 (patch)
tree63911adaab9d2160b13660c5a81383703047a271
parent92e58cd28759ff2132a78d37a058ca0c4b0cc018 (diff)
downloadfile-git-a01c49e324e31dbd62d54b46c1141b70de53d810.tar.gz
add a truncation warning and fix some size_t/int confusiog.
-rw-r--r--src/apprentice.c14
-rw-r--r--src/file.h8
-rw-r--r--src/print.c4
3 files changed, 16 insertions, 10 deletions
diff --git a/src/apprentice.c b/src/apprentice.c
index 375f23b3..dafb350f 100644
--- a/src/apprentice.c
+++ b/src/apprentice.c
@@ -46,7 +46,7 @@
#endif
#ifndef lint
-FILE_RCSID("@(#)$Id: apprentice.c,v 1.96 2006/10/27 14:51:28 christos Exp $")
+FILE_RCSID("@(#)$Id: apprentice.c,v 1.97 2006/10/27 14:57:32 christos Exp $")
#endif /* lint */
#define EATAB {while (isascii((unsigned char) *l) && \
@@ -88,9 +88,9 @@ struct magic_entry {
};
const int file_formats[] = { FILE_FORMAT_STRING };
-const int file_nformats = sizeof(file_formats) / sizeof(file_formats[0]);
+const size_t file_nformats = sizeof(file_formats) / sizeof(file_formats[0]);
const char *file_names[] = { FILE_FORMAT_NAME };
-const int file_nnames = sizeof(file_names) / sizeof(file_names[0]);
+const size_t file_nnames = sizeof(file_names) / sizeof(file_names[0]);
private int getvalue(struct magic_set *ms, struct magic *, const char **);
private int hextoint(int);
@@ -528,7 +528,7 @@ private int
parse(struct magic_set *ms, struct magic_entry **mentryp, uint32_t *nmentryp,
const char *line, int action)
{
- int i;
+ size_t i;
struct magic_entry *me;
struct magic *m;
const char *l = line;
@@ -837,7 +837,11 @@ GetDesc:
m->nospflag = 0;
for (i = 0; (m->desc[i++] = *l++) != '\0' && i < sizeof(m->desc); )
continue;
- m->desc[sizeof(m->desc) - 1] = '\0';
+ if (i == sizeof(m->desc)) {
+ m->desc[sizeof(m->desc) - 1] = '\0';
+ if (ms->flags & MAGIC_CHECK)
+ file_magwarn(ms, "description `%s' truncated", m->desc);
+ }
/*
* We only do this check while compiling, or if any of the magic
diff --git a/src/file.h b/src/file.h
index 0bbcdf8a..5827ed8c 100644
--- a/src/file.h
+++ b/src/file.h
@@ -27,7 +27,7 @@
*/
/*
* file.h - definitions for file(1) program
- * @(#)$Id: file.h,v 1.76 2006/06/08 22:48:51 christos Exp $
+ * @(#)$Id: file.h,v 1.77 2006/10/27 14:57:32 christos Exp $
*/
#ifndef __file_h__
@@ -295,6 +295,11 @@ protected size_t file_mbswidth(const char *);
protected const char *file_getbuffer(struct magic_set *);
protected ssize_t sread(int, void *, size_t);
+#ifndef COMPILE_ONLY
+extern const char *file_names[];
+extern const size_t file_nnames;
+#endif
+
#ifndef HAVE_STRERROR
extern int sys_nerr;
extern char *sys_errlist[];
@@ -322,6 +327,5 @@ int snprintf(char *, size_t, const char *, ...);
static const char *rcsid(const char *p) { \
return rcsid(p = id); \
}
-#else
#endif /* __file_h__ */
diff --git a/src/print.c b/src/print.c
index 89286713..b349306b 100644
--- a/src/print.c
+++ b/src/print.c
@@ -41,7 +41,7 @@
#include <time.h>
#ifndef lint
-FILE_RCSID("@(#)$Id: print.c,v 1.52 2006/06/08 22:48:51 christos Exp $")
+FILE_RCSID("@(#)$Id: print.c,v 1.53 2006/10/27 14:57:32 christos Exp $")
#endif /* lint */
#define SZOF(a) (sizeof(a) / sizeof(a[0]))
@@ -51,8 +51,6 @@ protected void
file_mdump(struct magic *m)
{
private const char optyp[] = { FILE_OPS };
- extern const char *file_names[];
- extern const int file_nnames;
(void) fputc('[', stderr);
(void) fprintf(stderr, ">>>>>>>> %d" + 8 - (m->cont_level & 7),