Plan 9 from Bell Labs’s /usr/web/sources/contrib/mospak/abaco-modern/abaco-base-href-guard.patch

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


abaco: getbase guard against relative BASE href

A page with a relative <BASE HREF="/foo"> lands in libhtml's
docinfo->base unresolved.  aurlval at libhtml/build.c:2885
ignores its `base` parameter (USED(base)), so the BASE
attribute value is stored as-is.  abaco's getbase returns
p->doc->base directly.  The next urlcombine call hits its
b==nil || !validurl(b) assertion and abaco dies with
"abaco: urlcombine: b==nil || !validurl(b)".

Guard p->doc->base with validurl in getbase.  An invalid (or
nil) BASE falls through to the page's actual URL — same
behaviour as a page with no BASE tag.  Pages that intended a
relative BASE meaningfully will resolve subsequent hrefs
against the page URL instead.  Not strictly HTML 4 conformant
but matches author intent in practice (a relative BASE is
almost always a typo for the page URL) and stops the crash.

The libhtml side is unfixed.  The proper fix is to make
aurlval resolve relative URLs against its `base` argument,
or have build.c's Tbase handler combine the new base with
the old.  Both require introducing a URL combiner inside
libhtml — out of scope for this single-line guard.

--- sys/src/cmd/abaco/util.c
+++ sys/src/cmd/abaco/util.c
@@ -365,7 +365,7 @@
 Rune *
 getbase(Page *p)
 {
-	if(p->doc)
+	if(p->doc && p->doc->base != nil && validurl(p->doc->base))
 		return p->doc->base;
 	if(p->url->act.r)
 		return p->url->act.r;

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.