* Fix 2 more bugs in OpenBSD file(1)

- ref: http://lolcathost.org/b/openbsd-file.patch
This commit is contained in:
pancake 2011-09-11 16:04:38 +02:00
parent 6afd85a447
commit bf463cae9e
2 changed files with 4 additions and 19 deletions

View File

@ -257,6 +257,7 @@ apprentice_1(struct r_magic_set *ms, const char *fn, int action,
return -1;
}
ms->file = fn; // fix use of ms->file before being initialized
if (action == FILE_COMPILE) {
rv = apprentice_load(ms, &magic, &nmagic, fn, action);
if (rv != 0)

View File

@ -44,28 +44,12 @@ int
file_printf(struct r_magic_set *ms, const char *fmt, ...)
{
va_list ap;
int len;
char *buf, *newstr;
int ret;
va_start(ap, fmt);
len = vasprintf(&buf, fmt, ap);
if (len < 0)
goto out;
ret = file_vprintf (ms, fmt, ap);
va_end(ap);
if (ms->o.buf != NULL) {
len = asprintf(&newstr, "%s%s", ms->o.buf, buf);
free(buf);
if (len < 0)
goto out;
free(ms->o.buf);
buf = newstr;
}
ms->o.buf = buf;
return 0;
out:
file_error(ms, errno, "vasprintf failed");
return -1;
return ret;
}
// copypasta to fix an OPENBSDBUG