Here's a config.def.h patch to prevent SETPROP from setting a property to an empty value. This will prevent errors in surf when hitting escape and to close dmenu when setting some surf XProperties, like the url.
--- surf.orig/config.def.h Thu Jan 14 16:31:24 2010 +++ surf/config.def.h Thu Jan 14 16:30:46 2010 @@ -10,7 +10,7 @@ #define SETPROP(p) { .v = (char *[]){ "/bin/sh", "-c", \ "prop=\"`xprop -id $1 $0 | cut -d '\"' -f 2 | dmenu`\" &&" \ - "xprop -id $1 -f $0 8s -set $0 \"$prop\"", \ + "[ -n \"$prop\" ] && xprop -id $1 -f $0 8s -set $0 \"$prop\"", \ p, winid, NULL } } #define MODKEY GDK_CONTROL_MASK static Key keys[] = {