char *BUF_strdup(const char *buf) { if (buf == NULL) { return NULL; } return BUF_strndup(buf, strlen(buf)); }
char *BUF_strdup(const char *str) { if (str == NULL) { return NULL; } return BUF_strndup(str, strlen(str)); }
/* split_host_and_port sets |*out_host| and |*out_port| to the host and port * parsed from |name|. It returns one on success or zero on error. Even when * successful, |*out_port| may be NULL on return if no port was specified. */ static int split_host_and_port(char **out_host, char **out_port, const char *name) { const char *host, *port = NULL; size_t host_len = 0; *out_host = NULL; *out_port = NULL; if (name[0] == '[') { /* bracketed IPv6 address */ const char *close = strchr(name, ']'); if (close == NULL) { return 0; } host = name + 1; host_len = close - host; if (close[1] == ':') { /* [IP]:port */ port = close + 2; } else if (close[1] != 0) { return 0; } } else { const char *colon = strchr(name, ':'); if (colon == NULL || strchr(colon + 1, ':') != NULL) { /* IPv6 address */ host = name; host_len = strlen(name); } else { /* host:port */ host = name; host_len = colon - name; port = colon + 1; } } *out_host = BUF_strndup(host, host_len); if (*out_host == NULL) { return 0; } if (port == NULL) { *out_port = NULL; return 1; } *out_port = OPENSSL_strdup(port); if (*out_port == NULL) { OPENSSL_free(*out_host); *out_host = NULL; return 0; } return 1; }
static int int_x509_param_set_hosts(X509_VERIFY_PARAM_ID *id, int mode, const char *name, size_t namelen) { char *copy; /* * Refuse names with embedded NUL bytes, except perhaps as final byte. * XXX: Do we need to push an error onto the error stack? */ if (namelen == 0) namelen = name ? strlen(name) : 0; else if (name && memchr(name, '\0', namelen > 1 ? namelen - 1 : namelen)) return 0; if (name && name[namelen - 1] == '\0') --namelen; if (mode == SET_HOST && id->hosts) { string_stack_free(id->hosts); id->hosts = NULL; } if (name == NULL || namelen == 0) return 1; copy = BUF_strndup(name, namelen); if (copy == NULL) return 0; if (id->hosts == NULL && (id->hosts = sk_OPENSSL_STRING_new_null()) == NULL) { OPENSSL_free(copy); return 0; } if (!sk_OPENSSL_STRING_push(id->hosts, copy)) { OPENSSL_free(copy); if (sk_OPENSSL_STRING_num(id->hosts) == 0) { sk_OPENSSL_STRING_free(id->hosts); id->hosts = NULL; } return 0; } return 1; }
int STORE_ATTR_INFO_set_cstr(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code, char *cstr, size_t cstr_size) { if (!attrs) { STOREerr(STORE_F_STORE_ATTR_INFO_SET_CSTR, ERR_R_PASSED_NULL_PARAMETER); return 0; } if (!ATTR_IS_SET(attrs, code)) { if ((attrs->values[code].cstring = BUF_strndup(cstr, cstr_size))) return 1; STOREerr(STORE_F_STORE_ATTR_INFO_SET_CSTR, ERR_R_MALLOC_FAILURE); return 0; } STOREerr(STORE_F_STORE_ATTR_INFO_SET_CSTR, STORE_R_ALREADY_HAS_A_VALUE); return 0; }
static int execute_heartbeat(HEARTBEAT_TEST_FIXTURE fixture) { int result = 0; SSL *s = fixture.s; unsigned char *payload = fixture.payload; unsigned char sent_buf[MAX_PRINTABLE_CHARACTERS + 1]; int return_value; unsigned const char *p; int actual_payload_len; s->rlayer.rrec.data = payload; s->rlayer.rrec.length = strlen((const char *)payload); *payload++ = TLS1_HB_REQUEST; s2n(fixture.sent_payload_len, payload); /* * Make a local copy of the request, since it gets overwritten at some * point */ memcpy((char *)sent_buf, (const char *)payload, sizeof(sent_buf)); return_value = fixture.process_heartbeat(s, s->rlayer.rrec.data, s->rlayer.rrec.length); if (return_value != fixture.expected_return_value) { printf("%s failed: expected return value %d, received %d\n", fixture.test_case_name, fixture.expected_return_value, return_value); result = 1; } /* * If there is any byte alignment, it will be stored in wbuf.offset. */ p = &(s->rlayer. wbuf.buf[fixture.return_payload_offset + s->rlayer.wbuf.offset]); actual_payload_len = 0; n2s(p, actual_payload_len); if (actual_payload_len != fixture.expected_payload_len) { printf("%s failed:\n expected payload len: %d\n received: %d\n", fixture.test_case_name, fixture.expected_payload_len, actual_payload_len); print_payload("sent", sent_buf, strlen((const char *)sent_buf)); print_payload("received", p, actual_payload_len); result = 1; } else { char *actual_payload = BUF_strndup((const char *)p, actual_payload_len); if (strcmp(actual_payload, fixture.expected_return_payload) != 0) { printf ("%s failed:\n expected payload: \"%s\"\n received: \"%s\"\n", fixture.test_case_name, fixture.expected_return_payload, actual_payload); result = 1; } OPENSSL_free(actual_payload); } if (result != 0) { printf("** %s failed **\n--------\n", fixture.test_case_name); } return result; }
char *BUF_strdup(const char *str) { if (str == NULL) return(NULL); return BUF_strndup(str, strlen(str)); }