Changeset eea72a1


Ignore:
Timestamp:
Sep 12, 2009, 7:37:37 PM (12 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
5118b32
Parents:
2340422
Message:
owl_new_sv: Escape non-utf8 strings before erroring with them.

Sending known non-utf8 text back into other code is just a bad
plan. In particular, multiline error messages become admin messages,
which results in their bodies getting sent to perl, which calls
owl_new_sv, and we would recurse infinitely.
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • perlconfig.c

    rd1b1cf6 reea72a1  
    2929    SvUTF8_on(ret);
    3030  } else {
    31     owl_function_error("Internal error! Non-UTF-8 string encountered:\n%s", str);
     31    char *escape = owl_escape_highbit(str);
     32    owl_function_error("Internal error! Non-UTF-8 string encountered:\n%s", escape);
     33    owl_free(escape);
    3234  }
    3335  return ret;
  • util.c

    r36486be reea72a1  
    758758  return 0;
    759759}
     760
     761char *owl_escape_highbit(const char *str)
     762{
     763  GString *out = g_string_new("");
     764  unsigned char c;
     765  while((c = (*str++))) {
     766    if(c == '\\') {
     767      g_string_append(out, "\\\\");
     768    } else if(c & 0x80) {
     769      g_string_append_printf(out, "\\x%02x", (int)c);
     770    } else {
     771      g_string_append_c(out, c);
     772    }
     773  }
     774  return g_string_free(out, 0);
     775}
Note: See TracChangeset for help on using the changeset viewer.