Drop unnecessary allocator return value checks

This commit is contained in:
Nikita Popov 2017-03-12 17:19:20 +01:00
parent e8c85a854b
commit edcabf6d07
13 changed files with 98 additions and 260 deletions

View File

@ -2493,9 +2493,6 @@ ZEND_API void* ZEND_FASTCALL _ecalloc(size_t nmemb, size_t size ZEND_FILE_LINE_D
void *p;
p = _safe_emalloc(nmemb, size, 0 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
if (UNEXPECTED(p == NULL)) {
return p;
}
memset(p, 0, size * nmemb);
return p;
}
@ -2510,9 +2507,6 @@ ZEND_API char* ZEND_FASTCALL _estrdup(const char *s ZEND_FILE_LINE_DC ZEND_FILE_
zend_error_noreturn(E_ERROR, "Possible integer overflow in memory allocation (1 * %zu + 1)", length);
}
p = (char *) _emalloc(length + 1 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
if (UNEXPECTED(p == NULL)) {
return p;
}
memcpy(p, s, length+1);
return p;
}
@ -2525,9 +2519,6 @@ ZEND_API char* ZEND_FASTCALL _estrndup(const char *s, size_t length ZEND_FILE_LI
zend_error_noreturn(E_ERROR, "Possible integer overflow in memory allocation (1 * %zu + 1)", length);
}
p = (char *) _emalloc(length + 1 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
if (UNEXPECTED(p == NULL)) {
return p;
}
memcpy(p, s, length);
p[length] = 0;
return p;

View File

@ -469,9 +469,6 @@ CWD_API char *virtual_getcwd_ex(size_t *length) /* {{{ */
*length = 1;
retval = (char *) emalloc(2);
if (retval == NULL) {
return NULL;
}
retval[0] = DEFAULT_SLASH;
retval[1] = '\0';
return retval;
@ -484,9 +481,6 @@ CWD_API char *virtual_getcwd_ex(size_t *length) /* {{{ */
*length = state->cwd_length+1;
retval = (char *) emalloc(*length+1);
if (retval == NULL) {
return NULL;
}
memcpy(retval, state->cwd, *length);
retval[0] = toupper(retval[0]);
retval[*length-1] = DEFAULT_SLASH;
@ -1331,13 +1325,6 @@ verify:
state->cwd_length = path_length;
tmp = erealloc(state->cwd, state->cwd_length+1);
if (tmp == NULL) {
CWD_STATE_FREE(&old_state);
#if VIRTUAL_CWD_DEBUG
fprintf (stderr, "Out of memory\n");
#endif
return 1;
}
state->cwd = (char *) tmp;
memcpy(state->cwd, resolved_path, state->cwd_length+1);
@ -1352,12 +1339,6 @@ verify:
} else {
state->cwd_length = path_length;
tmp = erealloc(state->cwd, state->cwd_length+1);
if (tmp == NULL) {
#if VIRTUAL_CWD_DEBUG
fprintf (stderr, "Out of memory\n");
#endif
return 1;
}
state->cwd = (char *) tmp;
memcpy(state->cwd, resolved_path, state->cwd_length+1);
@ -1420,10 +1401,6 @@ CWD_API char *virtual_realpath(const char *path, char *real_path) /* {{{ */
/* realpath("") returns CWD */
if (!*path) {
new_state.cwd = (char*)emalloc(1);
if (new_state.cwd == NULL) {
retval = NULL;
goto end;
}
new_state.cwd[0] = '\0';
new_state.cwd_length = 0;
if (VCWD_GETCWD(cwd, MAXPATHLEN)) {
@ -1433,10 +1410,6 @@ CWD_API char *virtual_realpath(const char *path, char *real_path) /* {{{ */
CWD_STATE_COPY(&new_state, &CWDG(cwd));
} else {
new_state.cwd = (char*)emalloc(1);
if (new_state.cwd == NULL) {
retval = NULL;
goto end;
}
new_state.cwd[0] = '\0';
new_state.cwd_length = 0;
}
@ -1452,7 +1425,6 @@ CWD_API char *virtual_realpath(const char *path, char *real_path) /* {{{ */
}
CWD_STATE_FREE(&new_state);
end:
return retval;
}
/* }}} */
@ -1855,9 +1827,6 @@ CWD_API FILE *virtual_popen(const char *command, const char *type) /* {{{ */
dir = CWDG(cwd).cwd;
ptr = command_line = (char *) emalloc(command_length + sizeof("cd '' ; ") + dir_length + extra+1+1);
if (!command_line) {
return NULL;
}
memcpy(ptr, "cd ", sizeof("cd ")-1);
ptr += sizeof("cd ")-1;
@ -1902,9 +1871,6 @@ CWD_API char *tsrm_realpath(const char *path, char *real_path) /* {{{ */
/* realpath("") returns CWD */
if (!*path) {
new_state.cwd = (char*)emalloc(1);
if (new_state.cwd == NULL) {
return NULL;
}
new_state.cwd[0] = '\0';
new_state.cwd_length = 0;
if (VCWD_GETCWD(cwd, MAXPATHLEN)) {
@ -1916,9 +1882,6 @@ CWD_API char *tsrm_realpath(const char *path, char *real_path) /* {{{ */
new_state.cwd_length = (int)strlen(cwd);
} else {
new_state.cwd = (char*)emalloc(1);
if (new_state.cwd == NULL) {
return NULL;
}
new_state.cwd[0] = '\0';
new_state.cwd_length = 0;
}

View File

@ -128,13 +128,11 @@ bc_divide (bc_num n1, bc_num n2, bc_num *quot, int scale)
else
extra = 0;
num1 = (unsigned char *) safe_emalloc (1, n1->n_len+n1->n_scale, extra+2);
if (num1 == NULL) bc_out_of_memory();
memset (num1, 0, n1->n_len+n1->n_scale+extra+2);
memcpy (num1+1, n1->n_value, n1->n_len+n1->n_scale);
len2 = n2->n_len + scale2;
num2 = (unsigned char *) safe_emalloc (1, len2, 1);
if (num2 == NULL) bc_out_of_memory();
memcpy (num2, n2->n_value, len2);
*(num2+len2) = 0;
n2ptr = num2;
@ -165,7 +163,6 @@ bc_divide (bc_num n1, bc_num n2, bc_num *quot, int scale)
/* Allocate storage for the temporary storage mval. */
mval = (unsigned char *) safe_emalloc (1, len2, 1);
if (mval == NULL) bc_out_of_memory ();
/* Now for the full divide algorithm. */
if (!zero)

View File

@ -61,7 +61,6 @@ _bc_new_num_ex (length, scale, persistent)
_bc_Free_list = temp->n_next;
} else {
temp = (bc_num) pemalloc (sizeof(bc_struct), persistent);
if (temp == NULL) bc_out_of_memory ();
}
#endif
temp->n_sign = PLUS;
@ -70,7 +69,6 @@ _bc_new_num_ex (length, scale, persistent)
temp->n_refs = 1;
/* PHP Change: malloc() -> pemalloc() */
temp->n_ptr = (char *) safe_pemalloc (1, length, scale, persistent);
if (temp->n_ptr == NULL) bc_out_of_memory();
temp->n_value = temp->n_ptr;
memset (temp->n_ptr, 0, length+scale);
return temp;

View File

@ -153,7 +153,6 @@ bc_out_num (bc_num num, int o_base, void (*out_char)(), int leading_zero)
bc_modulo (int_part, base, &cur_dig, 0);
/* PHP Change: malloc() -> emalloc() */
temp = (stk_rec *) emalloc (sizeof(stk_rec));
if (temp == NULL) bc_out_of_memory();
temp->digit = bc_num2long (cur_dig);
temp->next = digits;
digits = temp;

View File

@ -2564,14 +2564,9 @@ static php_iconv_err_t php_iconv_stream_filter_ctor(php_iconv_stream_filter *sel
const char *to_charset, size_t to_charset_len,
const char *from_charset, size_t from_charset_len, int persistent)
{
if (NULL == (self->to_charset = pemalloc(to_charset_len + 1, persistent))) {
return PHP_ICONV_ERR_ALLOC;
}
self->to_charset = pemalloc(to_charset_len + 1, persistent);
self->to_charset_len = to_charset_len;
if (NULL == (self->from_charset = pemalloc(from_charset_len + 1, persistent))) {
pefree(self->to_charset, persistent);
return PHP_ICONV_ERR_ALLOC;
}
self->from_charset = pemalloc(from_charset_len + 1, persistent);
self->from_charset_len = from_charset_len;
memcpy(self->to_charset, to_charset, to_charset_len);
@ -2614,9 +2609,7 @@ static int php_iconv_stream_filter_append_bucket(
}
out_buf_size = ocnt = prev_ocnt = initial_out_buf_size;
if (NULL == (out_buf = pemalloc(out_buf_size, persistent))) {
return FAILURE;
}
out_buf = pemalloc(out_buf_size, persistent);
pd = out_buf;
@ -2733,19 +2726,10 @@ static int php_iconv_stream_filter_append_bucket(
php_stream_bucket_append(buckets_out, new_bucket);
out_buf_size = ocnt = initial_out_buf_size;
if (NULL == (out_buf = pemalloc(out_buf_size, persistent))) {
return FAILURE;
}
out_buf = pemalloc(out_buf_size, persistent);
pd = out_buf;
} else {
if (NULL == (new_out_buf = perealloc(out_buf, new_out_buf_size, persistent))) {
if (NULL == (new_bucket = php_stream_bucket_new(stream, out_buf, (out_buf_size - ocnt), 1, persistent))) {
goto out_failure;
}
php_stream_bucket_append(buckets_out, new_bucket);
return FAILURE;
}
new_out_buf = perealloc(out_buf, new_out_buf_size, persistent);
pd = new_out_buf + (pd - out_buf);
ocnt += (new_out_buf_size - out_buf_size);
out_buf = new_out_buf;
@ -2877,9 +2861,7 @@ static php_stream_filter *php_iconv_stream_filter_factory_create(const char *nam
return NULL;
}
if (NULL == (inst = pemalloc(sizeof(php_iconv_stream_filter), persistent))) {
return NULL;
}
inst = pemalloc(sizeof(php_iconv_stream_filter), persistent);
if (php_iconv_stream_filter_ctor(inst, to_charset, to_charset_len, from_charset, from_charset_len, persistent) != PHP_ICONV_ERR_SUCCESS) {
pefree(inst, persistent);

View File

@ -746,74 +746,64 @@ php_mb_parse_encoding_list(const char *value, size_t value_length, const mbfl_en
size = n + MBSTRG(default_detect_order_list_size);
/* make list */
list = (const mbfl_encoding **)pecalloc(size, sizeof(mbfl_encoding*), persistent);
if (list != NULL) {
entry = list;
n = 0;
bauto = 0;
p1 = tmpstr;
do {
p2 = p = (char*)php_memnstr(p1, ",", 1, endp);
if (p == NULL) {
p = endp;
}
entry = list;
n = 0;
bauto = 0;
p1 = tmpstr;
do {
p2 = p = (char*)php_memnstr(p1, ",", 1, endp);
if (p == NULL) {
p = endp;
}
*p = '\0';
/* trim spaces */
while (p1 < p && (*p1 == ' ' || *p1 == '\t')) {
p1++;
}
p--;
while (p > p1 && (*p == ' ' || *p == '\t')) {
*p = '\0';
/* trim spaces */
while (p1 < p && (*p1 == ' ' || *p1 == '\t')) {
p1++;
}
p--;
while (p > p1 && (*p == ' ' || *p == '\t')) {
*p = '\0';
p--;
}
/* convert to the encoding number and check encoding */
if (strcasecmp(p1, "auto") == 0) {
if (!bauto) {
const enum mbfl_no_encoding *src = MBSTRG(default_detect_order_list);
const size_t identify_list_size = MBSTRG(default_detect_order_list_size);
size_t i;
bauto = 1;
for (i = 0; i < identify_list_size; i++) {
*entry++ = mbfl_no2encoding(*src++);
n++;
}
}
} else {
const mbfl_encoding *encoding = mbfl_name2encoding(p1);
if (encoding) {
*entry++ = encoding;
}
/* convert to the encoding number and check encoding */
if (strcasecmp(p1, "auto") == 0) {
if (!bauto) {
const enum mbfl_no_encoding *src = MBSTRG(default_detect_order_list);
const size_t identify_list_size = MBSTRG(default_detect_order_list_size);
size_t i;
bauto = 1;
for (i = 0; i < identify_list_size; i++) {
*entry++ = mbfl_no2encoding(*src++);
n++;
} else {
ret = 0;
}
}
p1 = p2 + 1;
} while (n < size && p2 != NULL);
if (n > 0) {
if (return_list) {
*return_list = list;
} else {
pefree(list, persistent);
}
} else {
pefree(list, persistent);
if (return_list) {
*return_list = NULL;
const mbfl_encoding *encoding = mbfl_name2encoding(p1);
if (encoding) {
*entry++ = encoding;
n++;
} else {
ret = 0;
}
ret = 0;
}
if (return_size) {
*return_size = n;
p1 = p2 + 1;
} while (n < size && p2 != NULL);
if (n > 0) {
if (return_list) {
*return_list = list;
} else {
pefree(list, persistent);
}
} else {
pefree(list, persistent);
if (return_list) {
*return_list = NULL;
}
if (return_size) {
*return_size = 0;
}
ret = 0;
}
if (return_size) {
*return_size = n;
}
efree(tmpstr);
}
@ -840,60 +830,50 @@ php_mb_parse_encoding_array(zval *array, const mbfl_encoding ***return_list, siz
i = zend_hash_num_elements(target_hash);
size = i + MBSTRG(default_detect_order_list_size);
list = (const mbfl_encoding **)pecalloc(size, sizeof(mbfl_encoding*), persistent);
if (list != NULL) {
entry = list;
bauto = 0;
n = 0;
ZEND_HASH_FOREACH_VAL(target_hash, hash_entry) {
convert_to_string_ex(hash_entry);
if (strcasecmp(Z_STRVAL_P(hash_entry), "auto") == 0) {
if (!bauto) {
const enum mbfl_no_encoding *src = MBSTRG(default_detect_order_list);
const size_t identify_list_size = MBSTRG(default_detect_order_list_size);
size_t j;
entry = list;
bauto = 0;
n = 0;
ZEND_HASH_FOREACH_VAL(target_hash, hash_entry) {
convert_to_string_ex(hash_entry);
if (strcasecmp(Z_STRVAL_P(hash_entry), "auto") == 0) {
if (!bauto) {
const enum mbfl_no_encoding *src = MBSTRG(default_detect_order_list);
const size_t identify_list_size = MBSTRG(default_detect_order_list_size);
size_t j;
bauto = 1;
for (j = 0; j < identify_list_size; j++) {
*entry++ = mbfl_no2encoding(*src++);
n++;
}
}
} else {
const mbfl_encoding *encoding = mbfl_name2encoding(Z_STRVAL_P(hash_entry));
if (encoding) {
*entry++ = encoding;
bauto = 1;
for (j = 0; j < identify_list_size; j++) {
*entry++ = mbfl_no2encoding(*src++);
n++;
} else {
ret = FAILURE;
}
}
i--;
} ZEND_HASH_FOREACH_END();
if (n > 0) {
if (return_list) {
*return_list = list;
} else {
pefree(list, persistent);
}
} else {
pefree(list, persistent);
if (return_list) {
*return_list = NULL;
const mbfl_encoding *encoding = mbfl_name2encoding(Z_STRVAL_P(hash_entry));
if (encoding) {
*entry++ = encoding;
n++;
} else {
ret = FAILURE;
}
ret = FAILURE;
}
if (return_size) {
*return_size = n;
i--;
} ZEND_HASH_FOREACH_END();
if (n > 0) {
if (return_list) {
*return_list = list;
} else {
pefree(list, persistent);
}
} else {
pefree(list, persistent);
if (return_list) {
*return_list = NULL;
}
if (return_size) {
*return_size = 0;
}
ret = FAILURE;
}
if (return_size) {
*return_size = n;
}
}
return ret;

View File

@ -217,9 +217,6 @@ PHPAPI void
mysqlnd_stats_init(MYSQLND_STATS ** stats, const size_t statistic_count, const zend_bool persistent)
{
*stats = pecalloc(1, sizeof(MYSQLND_STATS), persistent);
if (*stats == NULL) {
return;
}
(*stats)->values = pecalloc(statistic_count, sizeof(uint64_t), persistent);
(*stats)->triggers = pecalloc(statistic_count, sizeof(mysqlnd_stat_trigger), persistent);
(*stats)->in_trigger = FALSE;

View File

@ -567,24 +567,14 @@ static void php_snmp_getvalue(struct variable_list *vars, zval *snmpval, int val
dbuf = (char *)emalloc(val_len + 1);
}
if (!dbuf) {
php_error_docref(NULL, E_WARNING, "emalloc() failed: %s, fallback to static buffer", strerror(errno));
buf = &(sbuf[0]);
buflen = sizeof(sbuf) - 1;
break;
}
buf = dbuf;
buflen = val_len;
}
if((valueretrieval & SNMP_VALUE_PLAIN) && val_len > buflen){
if ((dbuf = (char *)emalloc(val_len + 1))) {
buf = dbuf;
buflen = val_len;
} else {
php_error_docref(NULL, E_WARNING, "emalloc() failed: %s, fallback to static buffer", strerror(errno));
}
dbuf = (char *)emalloc(val_len + 1);
buf = dbuf;
buflen = val_len;
}
if (valueretrieval & SNMP_VALUE_PLAIN) {
@ -972,11 +962,6 @@ static int php_snmp_parse_oid(zval *object, int st, struct objid_query *objid_qu
objid_query->array_output = ((st & SNMP_CMD_WALK) ? TRUE : FALSE);
if (Z_TYPE_P(oid) == IS_STRING) {
objid_query->vars = (snmpobjarg *)emalloc(sizeof(snmpobjarg));
if (objid_query->vars == NULL) {
php_error_docref(NULL, E_WARNING, "emalloc() failed while parsing oid: %s", strerror(errno));
efree(objid_query->vars);
return FALSE;
}
objid_query->vars[objid_query->count].oid = Z_STRVAL_P(oid);
if (st & SNMP_CMD_SET) {
if (Z_TYPE_P(type) == IS_STRING && Z_TYPE_P(value) == IS_STRING) {
@ -1001,11 +986,6 @@ static int php_snmp_parse_oid(zval *object, int st, struct objid_query *objid_qu
return FALSE;
}
objid_query->vars = (snmpobjarg *)safe_emalloc(sizeof(snmpobjarg), zend_hash_num_elements(Z_ARRVAL_P(oid)), 0);
if (objid_query->vars == NULL) {
php_error_docref(NULL, E_WARNING, "emalloc() failed while parsing oid array: %s", strerror(errno));
efree(objid_query->vars);
return FALSE;
}
objid_query->array_output = ( (st & SNMP_CMD_SET) ? FALSE : TRUE );
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(oid), tmp_oid) {
convert_to_string_ex(tmp_oid);
@ -1112,10 +1092,6 @@ static int netsnmp_session_init(php_snmp_session **session_p, int version, char
*session_p = (php_snmp_session *)emalloc(sizeof(php_snmp_session));
session = *session_p;
if (session == NULL) {
php_error_docref(NULL, E_WARNING, "emalloc() failed allocating session");
return (-1);
}
memset(session, 0, sizeof(php_snmp_session));
snmp_sess_init(session);
@ -1124,10 +1100,6 @@ static int netsnmp_session_init(php_snmp_session **session_p, int version, char
session->remote_port = SNMP_PORT;
session->peername = emalloc(MAX_NAME_LEN);
if (session->peername == NULL) {
php_error_docref(NULL, E_WARNING, "emalloc() failed while copying hostname");
return (-1);
}
/* we copy original hostname for further processing */
strlcpy(session->peername, hostname, MAX_NAME_LEN);
host_ptr = session->peername;
@ -1317,10 +1289,6 @@ static int netsnmp_session_set_contextEngineID(struct snmp_session *s, char * co
size_t ebuf_len = 32, eout_len = 0;
u_char *ebuf = (u_char *) emalloc(ebuf_len);
if (ebuf == NULL) {
php_error_docref(NULL, E_WARNING, "malloc failure setting contextEngineID");
return (-1);
}
if (!snmp_hex_to_binary(&ebuf, &ebuf_len, &eout_len, 1, contextEngineID)) {
php_error_docref(NULL, E_WARNING, "Bad engine ID value '%s'", contextEngineID);
efree(ebuf);

View File

@ -411,10 +411,6 @@ static int browscap_read_file(char *filename, browser_data *browdata, int persis
fh.type = ZEND_HANDLE_FP;
browdata->htab = pemalloc(sizeof *browdata->htab, persistent);
if (browdata->htab == NULL) {
return FAILURE;
}
zend_hash_init_ex(browdata->htab, 0, NULL,
persistent ? browscap_entry_dtor_persistent : browscap_entry_dtor, persistent, 0);

View File

@ -179,9 +179,7 @@ typedef struct _php_strip_tags_filter {
static int php_strip_tags_filter_ctor(php_strip_tags_filter *inst, const char *allowed_tags, size_t allowed_tags_len, int persistent)
{
if (allowed_tags != NULL) {
if (NULL == (inst->allowed_tags = pemalloc(allowed_tags_len, persistent))) {
return FAILURE;
}
inst->allowed_tags = pemalloc(allowed_tags_len, persistent);
memcpy((char *)inst->allowed_tags, allowed_tags, allowed_tags_len);
inst->allowed_tags_len = (int)allowed_tags_len;
} else {
@ -251,11 +249,6 @@ static php_stream_filter *strfilter_strip_tags_create(const char *filtername, zv
inst = pemalloc(sizeof(php_strip_tags_filter), persistent);
if (inst == NULL) { /* it's possible pemalloc returns NULL
instead of causing it to bail out */
return NULL;
}
if (filterparams != NULL) {
if (Z_TYPE_P(filterparams) == IS_ARRAY) {
zval *tmp;
@ -1219,10 +1212,7 @@ static php_conv_err_t php_conv_get_string_prop_ex(const HashTable *ht, char **pr
if ((tmpval = zend_hash_str_find((HashTable *)ht, field_name, field_name_len-1)) != NULL) {
zend_string *str = zval_get_string(tmpval);
if (NULL == (*pretval = pemalloc(ZSTR_LEN(str) + 1, persistent))) {
return PHP_CONV_ERR_ALLOC;
}
*pretval = pemalloc(ZSTR_LEN(str) + 1, persistent);
*pretval_len = ZSTR_LEN(str);
memcpy(*pretval, ZSTR_VAL(str), ZSTR_LEN(str) + 1);
zend_string_release(str);
@ -1485,9 +1475,7 @@ static int strfilter_convert_append_bucket(
}
out_buf_size = ocnt = initial_out_buf_size;
if (NULL == (out_buf = pemalloc(out_buf_size, persistent))) {
return FAILURE;
}
out_buf = pemalloc(out_buf_size, persistent);
pd = out_buf;
@ -1602,19 +1590,10 @@ static int strfilter_convert_append_bucket(
php_stream_bucket_append(buckets_out, new_bucket);
out_buf_size = ocnt = initial_out_buf_size;
if (NULL == (out_buf = pemalloc(out_buf_size, persistent))) {
return FAILURE;
}
out_buf = pemalloc(out_buf_size, persistent);
pd = out_buf;
} else {
if (NULL == (new_out_buf = perealloc(out_buf, new_out_buf_size, persistent))) {
if (NULL == (new_bucket = php_stream_bucket_new(stream, out_buf, (out_buf_size - ocnt), 1, persistent))) {
goto out_failure;
}
php_stream_bucket_append(buckets_out, new_bucket);
return FAILURE;
}
new_out_buf = perealloc(out_buf, new_out_buf_size, persistent);
pd = new_out_buf + (pd - out_buf);
ocnt += (new_out_buf_size - out_buf_size);
out_buf = new_out_buf;

View File

@ -861,11 +861,10 @@ PHPDBG_API int phpdbg_xml_vasprintf(char **buf, const char *format, zend_bool es
*buf = NULL;
if (cc >= 0) {
if ((*buf = emalloc(++cc)) != NULL) {
if ((cc = phpdbg_xml_vsnprintf(*buf, cc, format, escape_xml, ap)) < 0) {
efree(*buf);
*buf = NULL;
}
*buf = emalloc(++cc);
if ((cc = phpdbg_xml_vsnprintf(*buf, cc, format, escape_xml, ap)) < 0) {
efree(*buf);
*buf = NULL;
}
}

View File

@ -58,9 +58,8 @@
because the content is in *error_message now */
#define SMTP_ERROR_RESPONSE(response) { \
if (response && error_message) { \
if (NULL != (*error_message = ecalloc(1, sizeof(SMTP_ERROR_RESPONSE_SPEC) + strlen(response)))) { \
snprintf(*error_message, sizeof(SMTP_ERROR_RESPONSE_SPEC) + strlen(response), SMTP_ERROR_RESPONSE_SPEC, response); \
} \
*error_message = ecalloc(1, sizeof(SMTP_ERROR_RESPONSE_SPEC) + strlen(response)); \
snprintf(*error_message, sizeof(SMTP_ERROR_RESPONSE_SPEC) + strlen(response), SMTP_ERROR_RESPONSE_SPEC, response); \
efree(response); \
} \
}
@ -283,9 +282,7 @@ PHPAPI int TSendMail(char *host, int *error, char **error_message,
zend_string_free(headers_lc);
}
/* 128 is safe here, the specifier in snprintf isn't longer than that */
if (NULL == (*error_message = ecalloc(1, HOST_NAME_LEN + 128))) {
return FAILURE;
}
*error_message = ecalloc(1, HOST_NAME_LEN + 128);
snprintf(*error_message, HOST_NAME_LEN + 128,
"Failed to connect to mailserver at \"%s\" port %d, verify your \"SMTP\" "
"and \"smtp_port\" setting in php.ini or use ini_set()",
@ -559,9 +556,7 @@ static int SendText(char *RPath, char *Subject, char *mailTo, char *mailCc, char
/* Now that we've identified that we've a Bcc list,
remove it from the current header. */
if (NULL == (stripped_header = ecalloc(1, strlen(headers)))) {
return OUT_OF_MEMORY;
}
stripped_header = ecalloc(1, strlen(headers));
/* headers = point to string start of header
pos1 = pointer IN headers where the Bcc starts
'4' = Length of the characters 'bcc:'
@ -581,9 +576,7 @@ static int SendText(char *RPath, char *Subject, char *mailTo, char *mailCc, char
/* Simplify the code that we create a copy of stripped_header no matter if
we actually strip something or not. So we've a single efree() later. */
if (headers && !stripped_header) {
if (NULL == (stripped_header = estrndup(headers, strlen(headers)))) {
return OUT_OF_MEMORY;
}
stripped_header = estrndup(headers, strlen(headers));
}
if ((res = Post("DATA\r\n")) != SUCCESS) {
@ -659,9 +652,7 @@ static int SendText(char *RPath, char *Subject, char *mailTo, char *mailCc, char
static int addToHeader(char **header_buffer, const char *specifier, char *string)
{
if (NULL == (*header_buffer = erealloc(*header_buffer, strlen(*header_buffer) + strlen(specifier) + strlen(string) + 1))) {
return 0;
}
*header_buffer = erealloc(*header_buffer, strlen(*header_buffer) + strlen(specifier) + strlen(string) + 1);
sprintf(*header_buffer + strlen(*header_buffer), specifier, string);
return 1;
}
@ -688,9 +679,7 @@ static int PostHeader(char *RPath, char *Subject, char *mailTo, char *xheaders)
size_t i;
if (xheaders) {
if (NULL == (headers_lc = estrdup(xheaders))) {
return OUT_OF_MEMORY;
}
headers_lc = estrdup(xheaders);
for (i = 0; i < strlen(headers_lc); i++) {
headers_lc[i] = tolower(headers_lc[i]);
}