From: Sterling Hughes Date: Sat, 15 Sep 2001 16:00:47 +0000 (+0000) Subject: properly grab field and value pairs, plus avoid a segfault when errmsg isn't X-Git-Tag: PRE_SUBST_Z_MACROS~100 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=236bcdb514684f7791241725fcb993135d44fc74;p=php properly grab field and value pairs, plus avoid a segfault when errmsg isn't defined --- diff --git a/ext/xslt/sablot.c b/ext/xslt/sablot.c index 4012b4050d..26af287734 100644 --- a/ext/xslt/sablot.c +++ b/ext/xslt/sablot.c @@ -1435,7 +1435,7 @@ static MH_ERROR error_print(void *user_data, SablotHandle proc, MH_ERROR code, M char *ptr; /* Pointer to the location of the ':' (separator) */ int pos; /* Position of the ':' (separator) */ int len; /* Length of the string */ - + len = strlen(*fields); /* Grab the separator's position */ @@ -1507,8 +1507,8 @@ static MH_ERROR error_print(void *user_data, SablotHandle proc, MH_ERROR code, M key = emalloc(pos + 1); val = emalloc((len - pos) + 1); - strlcpy(key, *fields, pos); - strlcpy(val, *fields + pos + 1, len - pos - 1); + strlcpy(key, *fields, pos + 1); + strlcpy(val, *fields + pos + 1, len - pos); /* Check to see whether or not we want to save the data */ if (!strcmp(key, "msg")) { @@ -1517,7 +1517,7 @@ static MH_ERROR error_print(void *user_data, SablotHandle proc, MH_ERROR code, M else if (!strcmp(key, "line")) { errline = estrdup(val); } - + /* Cleanup */ if (key) efree(key); if (val) efree(val); @@ -1531,6 +1531,10 @@ static MH_ERROR error_print(void *user_data, SablotHandle proc, MH_ERROR code, M errline = estrndup("none", sizeof("none") - 1); } + if (!errmsg) { + errmsg = estrndup("unkown error", sizeof("unkown error") - 1); + } + /* Allocate the message buffer and copy the data onto it */ msgbuf = emalloc((sizeof(msgformat) - 4) + strlen(errmsg) + strlen(errline) + 1); sprintf(msgbuf, msgformat, errline, errmsg);