]> granicus.if.org Git - file/commitdiff
add a truncation warning and fix some size_t/int confusiog.
authorChristos Zoulas <christos@zoulas.com>
Fri, 27 Oct 2006 14:57:32 +0000 (14:57 +0000)
committerChristos Zoulas <christos@zoulas.com>
Fri, 27 Oct 2006 14:57:32 +0000 (14:57 +0000)
src/apprentice.c
src/file.h
src/print.c

index 375f23b396b11c57df0bca24faddcde7b114ded3..dafb350f5a62bbcf67faa963cd17b18547b43b0f 100644 (file)
@@ -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
index 0bbcdf8a15a48923395903132d407c583b4df5b7..5827ed8c6a5e66e8e0cd112ea6fd5b67a70cb3d9 100644 (file)
@@ -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__ */
index 89286713c98debdaf37bbbed8ba318f1a64d9815..b349306b39e9b46093a7117856c4ab3dd5621aed 100644 (file)
@@ -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),