summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlum <lum@cvs.openbsd.org>2011-12-05 07:17:03 +0000
committerlum <lum@cvs.openbsd.org>2011-12-05 07:17:03 +0000
commitb5ad0bf29a3bbefd27f41c46100d2daa6bef3950 (patch)
tree997c5623a4a47bf645dfacd75fed197d2958fdb1
parent505ea44a9eb1c24d838e61a8b022e5188b235c87 (diff)
Use absolute filenames while pushing and popping off the stack.
This fixes a segv discovered by Olivier A and reported to Sunil Nimmagadda, who provided the actual fix. Tested by myself and Oliver A.
-rw-r--r--usr.bin/mg/tags.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/usr.bin/mg/tags.c b/usr.bin/mg/tags.c
index 0796781117d..5ee9a9965bf 100644
--- a/usr.bin/mg/tags.c
+++ b/usr.bin/mg/tags.c
@@ -208,7 +208,7 @@ pushtag(char *tok)
{
struct ctag *res;
struct tagpos *s;
- char *bname;
+ char bname[NFILEN];
int doto, dotline;
if ((res = searchtag(tok)) == NULL)
@@ -216,7 +216,17 @@ pushtag(char *tok)
doto = curwp->w_doto;
dotline = curwp->w_dotline;
- bname = curbp->b_bname;
+ /* record absolute filenames. Fixes issues when mg's cwd is not the
+ * same as buffer's directory.
+ */
+ if (strlcpy(bname, curbp->b_cwd, sizeof(bname)) >= sizeof(bname)) {
+ ewprintf("filename too long");
+ return (FALSE);
+ }
+ if (strlcat(bname, curbp->b_bname, sizeof(bname)) >= sizeof(bname)) {
+ ewprintf("filename too long");
+ return (FALSE);
+ }
if (loadbuffer(res->fname) == FALSE)
return (FALSE);
@@ -227,8 +237,8 @@ pushtag(char *tok)
return (FALSE);
}
if ((s->bname = strdup(bname)) == NULL) {
- ewprintf("Out of memory");
- return (FALSE);
+ ewprintf("Out of memory");
+ return (FALSE);
}
s->doto = doto;
s->dotline = dotline;