summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristos Zoulas <christos@zoulas.com>2004-10-12 14:55:09 +0000
committerChristos Zoulas <christos@zoulas.com>2004-10-12 14:55:09 +0000
commit38640f9d0b4508ed9202b861bcd3a43ba79c34e9 (patch)
tree00e86e64c30fb8ef628ce017d2080cbd18b988b9
parent0099a385c0facdb62f5ad1b885f91bd0b16cbcd9 (diff)
downloadfile-git-38640f9d0b4508ed9202b861bcd3a43ba79c34e9.tar.gz
Fix stack overwrire on 0 length strings.
-rw-r--r--ChangeLog7
-rw-r--r--src/softmagic.c24
2 files changed, 18 insertions, 13 deletions
diff --git a/ChangeLog b/ChangeLog
index 9e5ad6e8..2a0972f3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,9 @@
-2004-09-27 11:30 christos Zoulas <christos@zoulas.com>
+2004 10-12 10:50 Christos Zoulas <christos@zoulas.com>
+
+ * Fix stack overwriting on 0 length strings: Tim Waugh
+ <twaugh@redhat.com>
+
+2004-09-27 11:30 Christos Zoulas <christos@zoulas.com>
* Remove 3rd and 4th copyright clause; approved by Ian Darwin.
diff --git a/src/softmagic.c b/src/softmagic.c
index 6e9f4abc..5b832154 100644
--- a/src/softmagic.c
+++ b/src/softmagic.c
@@ -39,7 +39,7 @@
#ifndef lint
-FILE_RCSID("@(#)$Id: softmagic.c,v 1.67 2004/09/11 19:15:58 christos Exp $")
+FILE_RCSID("@(#)$Id: softmagic.c,v 1.68 2004/10/12 14:55:09 christos Exp $")
#endif /* lint */
private int match(struct magic_set *, struct magic *, uint32_t,
@@ -422,27 +422,27 @@ mconvert(struct magic_set *ms, union VALUETYPE *p, struct magic *m)
return 1;
case FILE_STRING:
{
- int n;
+ size_t len;
/* Null terminate and eat *trailing* return */
p->s[sizeof(p->s) - 1] = '\0';
- n = strlen(p->s) - 1;
- if (p->s[n] == '\n')
- p->s[n] = '\0';
+ len = strlen(p->s);
+ if (len && p->s[len - 1] == '\n')
+ p->s[len - 1] = '\0';
return 1;
}
case FILE_PSTRING:
{
char *ptr1 = p->s, *ptr2 = ptr1 + 1;
- unsigned int n = *p->s;
- if (n >= sizeof(p->s))
- n = sizeof(p->s) - 1;
- while (n--)
+ size_t len = *p->s;
+ if (len >= sizeof(p->s))
+ len = sizeof(p->s) - 1;
+ while (len--)
*ptr1++ = *ptr2++;
*ptr1 = '\0';
- n = strlen(p->s) - 1;
- if (p->s[n] == '\n')
- p->s[n] = '\0';
+ len = strlen(p->s);
+ if (len && p->s[len - 1] == '\n')
+ p->s[len - 1] = '\0';
return 1;
}
case FILE_BESHORT: