[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: buffer write bug in mg
- To: tech_(_at_)_openbsd_(_dot_)_org
- Subject: Re: buffer write bug in mg
- From: Han Boetes <han_(_at_)_mijncomputer_(_dot_)_nl>
- Date: Tue, 4 Apr 2006 12:00:33 +0200
- Mail-followup-to: tech_(_at_)_openbsd_(_dot_)_org
Kjell Wooding wrote:
> While I'm here, use basename() instead of some custom stuff
Building on Linux resulted in this warning:
buffer.c:626: warning: passing arg 1 of `__xpg_basename' discards qualifiers from pointer target type
>From basename(3):
CAVEATS
basename() returns a pointer to internal static storage space that will
be overwritten by subsequent calls.
So I'd like to suggest this extra patch:
--- /usr/src/usr.bin/mg/buffer.c Tue Apr 4 11:58:14 2006
+++ buffer.c Tue Apr 4 11:52:40 2006
@@ -622,8 +622,11 @@ baugname(char *bn, const char *fn, size_
{
int count;
size_t remain, len;
+ char *fn_dup;
- len = strlcpy(bn, basename(fn), bs);
+ fn_dup = strdup(fn);
+ len = strlcpy(bn, basename(fn_dup), bs);
+ free(fn_dup);
if (len >= bs)
return (FALSE);
# Han
Visit your host, monkey.org