Scripts’R’Us: Remote Crashing Gajim

Gajim-Quitter is a little tool that registers a Jabber account, and sends well-formed, but invalid messages to the Gajim lead developer and the Gajim groupchat. Due to a bug, the jabber client Gajim crashes on receiving invalid (yet well-formed) namespace-malformed XML – namely tags with an undefined namespace.

Gajim-Quitter was coded in expect(1); programming it was quite interesting, these two articles (and the relevant RFCs and XEPs) helped me a lot. It would probably be a fun exercise for beginner-level programming courses to build a simple Jabber client.

If you want to be safe, use another Jabber client until the issue is fixed.

Update: Shortly after publishing this program it has come to my attention that the problem cannot be fixed in the client. Thus, the specification will probably be changed to require that servers check the transmitted XML for validity, which would in turn mean that everyone sending malformed XML will be disconnected.

29. Juni 2008 von admin
Kategorien: Misantropie als Bewältigungsstrategie, Originärer Inhalt, Technik | Schlagwörter: , , | Schreibe einen Kommentar

Constructing a regular expression that matches URIs

URI matching is commonly needed, most notably for URL matching – chat clients use this to create links in what is otherwise plain (and not hyper-) text. However, many regexes that are supposed to do exactly that fail on encountering uncommon, yet valid characters, because programmers don’t follow the RFC (many probably don’t even read it).

Additionally, users are stupid: While according to RFC 3986, chevrons should be used to designate URIs, often people use parentheses. When developers try to compensate for this, they create undesired – and more than often unexpected – behaviour: Links created from perfectly valid URIs are suddenly broken – see, for example, the chat client Gajim (and also the bugtracker / wiki Trac).

According to RFC 3986, subsection 1.1.1 , URI[s] begin[s] with a scheme name, which, according to subsection 3.1 consist of a sequence of characters beginning with a letter and followed by any combination of letters, digits, plus (“+”), period (“.”), or hyphen (“-“). Therefore, the correct regular expression for a scheme name is [A-Za-z][A-Za-z0-9\+\.\-]* .

After the scheme name, a colon (“:”) follows – the rest is scheme-specifix synthax; according to sections 2.2 and 2.3 we only know it uses a limited set of characters, namely those reserved for delimiting data (“:”, “/”, “?”, “#”, “[“, “]”, “@”, “!”, “$”, “&”, “‘”, “(“, “)”, “*”, “+”, “,”, “;”, “=”) and unreserved ones, which include uppercase and lowercase letters, decimal digits, hyphen, period, underscore, and tilde. This extends the regular expression to [A-Za-z][A-Za-z0-9\+\.\-]*:[A-Za-z0-9\.\-_~:/\?#\[\]@!\$&'\(\)\*\+,;=]+ – metacharacters (“[“, “\”, “$”, “.” “?”, “*”, “+” “(“, “)”) and the range specifier (“-“) properly encoded, of course.

“But wait”, you may be thinking right now, “how can I include other characters – umlauts, for example – in URIs, then ?” Well, you can’t. But you can describe a resource that contains characters not listed in the above paragraph by means of percent-encoding, a method detailed in section 2.1 to represent a data octet in a component when that octet’s corresponding character is outside the allowed set or is being used as a delimiter of, or within, the component. A percent-encoded character takes the form of a percent character (“%”), followed by two hexadecimal digits – the space character, for example, is encoded as “%20″. This gives us the expression %[A-Fa-f0-9]{2} , which can be added to the existing URI matching expression: [A-Za-z][A-Za-z0-9\+\.\-]*:([A-Za-z0-9\.\-_~:/\?#\[\]@!\$&'\(\)\*\+,;=]|%[A-Fa-f0-9]{2})+ will catch any valid URI (and probably some invalid ones too).

Now, what about the parenthesis problem that surfaced in the beginning ? A simple solution is just to define an additional expression that matches on URIs, but only if they are preceeded by an opening parenthesis (this feature is called “positive lookbehind”) and followed by a closing parenthesis (“positive lookahead”). We get (?<=\()[A-Za-z][A-Za-z0-9\+\.\-]*:([A-Za-z0-9\.\-_~:/\?#\[\]@!\$&'\(\)\*\+,;=]|%[A-Fa-f0-9]{2})+(?=\)) . Combining the two massive expressions by means of a simple OR yields the final result: ((?<=\()[A-Za-z][A-Za-z0-9\+\.\-]*:([A-Za-z0-9\.\-_~:/\?#\[\]@!\$&'\(\)\*\+,;=]|%[A-Fa-f0-9]{2})+(?=\)))|([A-Za-z][A-Za-z0-9\+\.\-]*:([A-Za-z0-9\.\-_~:/\?#\[\]@!\$&'\(\)\*\+,;=]|%[A-Fa-f0-9]{2})+) .

Update: Shortly after Gajim implemented it, it became clear that I had forgotten to escape the literal minus sign (“-“), which wouldn’t be matched then. This has since been corrected (in this post and in Gajim).

Since regular expressions can be locale-sensitive, I suggest using the C locale.

26. Juni 2008 von admin
Kategorien: Originärer Inhalt, Technik | Schlagwörter: , , | Schreibe einen Kommentar

Mental Order Defense

My dream girl visits me in the middle of the night.
(SVG) Background is Night Sky One by EuroMagic.

20. Juni 2008 von admin
Kategorien: !xkcd, Originärer Inhalt | Schreibe einen Kommentar

Vierkanal minus Schäuble u. Ä.

17. Juni 2008 von admin
Kategorien: Linkschleuder, Misantropie als Bewältigungsstrategie | Schlagwörter: , | Schreibe einen Kommentar

Anbiedern und gewinnen !

Zum Bloggen verwende verwendete ich Serendipity, kurz S9y. Wenn ich mich recht erinnern kann, empfahl mein Lieblingshoster ebendies – ich kannte sonst nur die andere Weblog-Software und die hat offenbar keinen besonders guten Ruf. Nungut, ich bin zufrieden, auch wenn ich PHP (die Sprache, in der S9y geschrieben ist) immer noch nicht mag.

Anlass dieses Beitrags ist das Erscheinen eines neuen Buches zu S9y – oder vielmehr das Gewinnspiel zum Serendipity-Handbuch: Allein durch das Verlinken habe ich wohl eine reelle 3-zu-234-Chance (Anzahl der aktuellen Trackbacks minus zwei minus die paar, die gar nicht gewinnen wollen, plus “manuelle” Trackbacks), weitere zwei Exemplare gehen an die Spaßvögel, die die Preisfragen am anbiederndsten beantworten (via Wohnzimmerhostblogger). Nungut, frisch ans Werk !

Preisfrage 1: Aus welchem Grund sollte man sich das Buch eigentlich kaufen, wenn man es nicht gerade gewinnt?

Nun, das Inhaltsverzeichnis schaut enorm aus, 752 Seiten sind wohl auch tatsächlich eine Menge Platz für Inhalte (zum Vergleich: Schneiers “Angewandte Kryptografie” hat 784). Das Probekapitel behandelt leider “nur” die Einrichtung der Software – etwas, womit ich nun keinerlei Erfahrung habe (dank an den Hoster an dieser Stelle) und was ich wohl auch nicht mehr all zu oft brauchen werde – liest sich jedoch recht flüssig und vor allem sehr strukturiert. Die Frage finde ich aber doch reichlich dämlich – ich kenne das Buch doch gar nicht ! Genau diese Tatsache wäre zwar ein guter Grund, es mir zu überlassen (in der Hoffnung, dass ich eine qualifizierte Rezension schreiben möge), schlussendlich lässt sich mit dieser Antwort doch wohl keinen Blumentopf Buch gewinnen. Daher entschied ich mich dann doch lieber dazu, einen thematisch passenden Haiku zu schreiben (lächerlich mache ich mich hier, in der Hoffnung, dass es gewitzt genug rüberkommt für einen Gewinn):

Bloggen wollte ich,
wählte Serendipity;
mir fehlt ein Handbuch.

Wunderbar schwachsinnig, nicht ? Schon Speeblick habe ich ja mit einem spontan erfundenen Slogan verzaubert, hoffentlich klappt das alles hier nochmal; also auch mit dem Gewinnen und so.

Preisfrage 2: Was gefällt euch am besten an Serendipity?

Ganz klar Spartacus, das mir, dem Bloglaien, ein einfaches Plugin-Management ermöglicht. Ähnlich wie APT möchte ich es nicht mehr missen; sollte ich je auf ein anderes Blogsystem umsteigen, muss dies etwas vergleichbares vorweisen können – als Ausnahme denkbar wäre wohl nur die Totbaumversion.

P.S.: Na, wie isses – würde ich mich gut als Bloghure Werbeblogger machen ?

16. Juni 2008 von admin
Kategorien: In eigener Sache, Linkschleuder, Technik | Schlagwörter: , | Schreibe einen Kommentar

← Ältere Artikel

Neuere Artikel →