diff options
author | Jindrich Novy <jnovy@redhat.com> | 2008-04-03 13:47:05 +0200 |
---|---|---|
committer | Jindrich Novy <jnovy@redhat.com> | 2008-04-03 13:49:09 +0200 |
commit | 1a269ccd3cc3be1bb5763f23621c63b5ac199c92 (patch) | |
tree | 9d1769d08ea83b573df90a2c8c6f1cd19db96e5a /build | |
parent | 58b9fb501d09ade85eae216d26cf51e31bb71e9d (diff) | |
download | rpm-1a269ccd3cc3be1bb5763f23621c63b5ac199c92.tar.gz rpm-1a269ccd3cc3be1bb5763f23621c63b5ac199c92.tar.bz2 rpm-1a269ccd3cc3be1bb5763f23621c63b5ac199c92.zip |
Don't use static buffers in parseForRegexLang()
- use dynamic allocation instead to avoid overflows
- also update addFile(), which is actually the only function
that calls parseForRegexLang()
Diffstat (limited to 'build')
-rw-r--r-- | build/files.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/build/files.c b/build/files.c index 0277acca3..6860a01bc 100644 --- a/build/files.c +++ b/build/files.c @@ -756,7 +756,7 @@ static int parseForRegexLang(const char * fileName, char ** lang) static int initialized = 0; static int hasRegex = 0; static regex_t compiledPatt; - static char buf[BUFSIZ]; + char *buf; int x; regmatch_t matches[2]; const char *s; @@ -782,12 +782,15 @@ static int parseForRegexLang(const char * fileName, char ** lang) /* Got match */ s = fileName + matches[1].rm_eo - 1; x = matches[1].rm_eo - matches[1].rm_so; + buf = xmalloc(x+1); buf[x] = '\0'; - while (x) { - buf[--x] = *s--; - } + memcpy(buf, s, x); if (lang) *lang = buf; + else { + free(buf); + return 1; + } return 0; } @@ -1377,7 +1380,6 @@ static rpmRC addFile(FileList fl, const char * diskURL, gid_t fileGid; const char *fileUname; const char *fileGname; - char *lang; /* Path may have prepended buildRootURL, so locate the original filename. */ /* @@ -1515,9 +1517,7 @@ static rpmRC addFile(FileList fl, const char * diskURL, *ncl++ = *ocl; *ncl = '\0'; } - } else if (! parseForRegexLang(fileURL, &lang)) { - flp->langs = xstrdup(lang); - } else { + } else if (parseForRegexLang(fileURL, &flp->langs)) { flp->langs = xstrdup(""); } |