And a few variables around.
There remain cases where the accepted pointer is const, yet the returned
pointer is written to.
Partly addressing (glibc 2.43):
```
* For ISO C23, the functions bsearch, memchr, strchr, strpbrk, strrchr,
strstr, wcschr, wcspbrk, wcsrchr, wcsstr and wmemchr that return
pointers into their input arrays now have definitions as macros that
return a pointer to a const-qualified type when the input argument is
a pointer to a const-qualified type.
```
Ref: https://lists.gnu.org/archive/html/info-gnu/2026-01/msg00005.html
Reported-by: Rudi Heitbaum
Ref: #20420
Closes #20421
return FALSE;
else {
/* there must be a dot present, but that dot must not be a trailing dot */
- char *dot = memchr(domain, '.', len);
+ const char *dot = memchr(domain, '.', len);
if(dot) {
size_t i = dot - domain;
if((len - i) > 1)
static CURLcode dict_do(struct Curl_easy *data, bool *done)
{
- char *word;
+ const char *word;
char *eword = NULL;
char *ppath;
char *database = NULL;
/* encode each label and store it in the QNAME */
while(*hostp) {
size_t labellen;
- char *dot = strchr(hostp, '.');
+ const char *dot = strchr(hostp, '.');
if(dot)
labellen = dot - hostp;
else
if(data->set.str[STRING_FTPPORT] &&
(strlen(data->set.str[STRING_FTPPORT]) > 1)) {
- char *ip_end = NULL;
+ const char *ip_end = NULL;
#ifdef USE_IPV6
if(*string_ftpport == '[') {
if((ftpc->count1 == 0) &&
(ftpcode == 229)) {
/* positive EPSV response */
- char *ptr = strchr(str, '(');
+ const char *ptr = strchr(str, '(');
if(ptr) {
char sep;
ptr++;
const char *hd, size_t hdlen)
{
struct SingleRequest *k = &data->req;
- char *ptr = memchr(hd, 0x00, hdlen);
+ const char *ptr = memchr(hd, 0x00, hdlen);
if(ptr) {
/* this is bad, bail out */
failf(data, "Nul byte in header");
struct connectdata *conn = data->conn;
CURLcode result = CURLE_OK;
struct SingleRequest *k = &data->req;
- char *end_ptr;
+ const char *end_ptr;
bool leftover_body = FALSE;
/* we have bytes for the next header, make sure it is not a folded header
if(compare_header_names(curr->data, next->data) == 0) {
struct dynbuf buf;
- char *colon_next;
- char *val_next;
+ const char *colon_next;
+ const char *val_next;
curlx_dyn_init(&buf, CURL_MAX_HTTP_HEADER);
semi-colon, are not added to this list.
*/
for(l = data->set.headers; l; l = l->next) {
- char *dupdata, *ptr;
- char *sep = strchr(l->data, ':');
+ char *dupdata;
+ const char *ptr;
+ const char *sep = strchr(l->data, ':');
if(!sep)
sep = strchr(l->data, ';');
if(!sep || (*sep == ':' && !*(sep + 1)))
for(index = 0; index < num_query_components; index++) {
const char *in_key;
size_t in_key_len;
- char *offset;
+ const char *offset;
size_t query_part_len = curlx_dyn_len(&query_array[index]);
char *query_part = curlx_dyn_ptr(&query_array[index]);
any order */
bool our_login = FALSE; /* found our login name */
bool done = FALSE;
- char *netrcbuffer;
+ const char *netrcbuffer;
struct dynbuf token;
struct dynbuf *filebuf = &store->filebuf;
DEBUGASSERT(!*passwordp);
tok = ++tok_end;
}
if(!done) {
- char *nl = NULL;
+ const char *nl = NULL;
if(tok)
nl = strchr(tok, '\n');
if(!nl)
}
do {
- char *line = curlx_dyn_ptr(&pp->recvbuf);
- char *nl = memchr(line, '\n', curlx_dyn_len(&pp->recvbuf));
+ const char *line = curlx_dyn_ptr(&pp->recvbuf);
+ const char *nl = memchr(line, '\n', curlx_dyn_len(&pp->recvbuf));
if(nl) {
/* a newline is CRLF in pp-talk, so the CR is ignored as
the line is not really terminated until the LF comes */
}
else if(len > 3) {
/* Does the server support APOP authentication? */
- char *lt;
- char *gt = NULL;
+ const char *lt;
+ const char *gt = NULL;
/* Look for the APOP timestamp */
lt = memchr(line, '<', len);
if(gt) {
/* the length of the timestamp, including the brackets */
size_t timestamplen = gt - lt + 1;
- char *at = memchr(lt, '@', timestamplen);
+ const char *at = memchr(lt, '@', timestamplen);
/* If the timestamp does not contain '@' it is not (as required by
RFC-1939) conformant to the RFC-822 message id syntax, and we
therefore do not use APOP authentication. */
int himq[256];
int him_preferred[256];
int subnegotiation[256];
- char *subopt_ttype; /* Set with suboption TTYPE */
- char *subopt_xdisploc; /* Set with suboption XDISPLOC */
+ const char *subopt_ttype; /* Set with suboption TTYPE */
+ const char *subopt_xdisploc; /* Set with suboption XDISPLOC */
unsigned short subopt_wsx; /* Set with suboption NAWS */
unsigned short subopt_wsy; /* Set with suboption NAWS */
TelnetReceive telrcv_state;
for(head = data->set.telnet_options; head && !result; head = head->next) {
size_t olen;
- char *option = head->data;
- char *arg;
- char *sep = strchr(option, '=');
+ const char *option = head->data;
+ const char *arg;
+ const char *sep = strchr(option, '=');
if(sep) {
olen = sep - option;
arg = ++sep;
return CURLE_BAD_FUNCTION_ARGUMENT;
/* Add the variable if it fits */
if(len + tmplen < (int)sizeof(temp) - 6) {
- char *s = strchr(v->data, ',');
+ const char *s = strchr(v->data, ',');
if(!s)
len += curl_msnprintf((char *)&temp[len], sizeof(temp) - len,
"%c%s", CURL_NEW_ENV_VAR, v->data);
}
else {
/* check whether the URL's port matches */
- char *ptr_next = strchr(ptr, ':');
+ const char *ptr_next = strchr(ptr, ':');
if(ptr_next) {
curl_off_t port_to_match;
if(!curlx_str_number(&ptr, &port_to_match, 0xffff) &&
*
* We need somewhere to put the embedded details, so do that first.
*/
- char *ptr;
+ const char *ptr;
DEBUGASSERT(login);
/* if necessary, replace the host content with a URL decoded version */
static CURLUcode urldecode_host(struct dynbuf *host)
{
- char *per = NULL;
+ const char *per;
const char *hostname = curlx_dyn_ptr(host);
per = strchr(hostname, '%');
if(!per)
/* remove the last segment from the output buffer */
size_t len = curlx_dyn_len(&out);
if(len) {
- char *ptr = curlx_dyn_ptr(&out);
- char *last = memrchr(ptr, '/', len);
+ const char *ptr = curlx_dyn_ptr(&out);
+ const char *last = memrchr(ptr, '/', len);
if(last)
/* trim the output at the slash */
curlx_dyn_setlen(&out, last - ptr);
if(user && *user) {
/* Check we have a domain name or UPN present */
- char *p = strpbrk(user, "\\/@");
+ const char *p = strpbrk(user, "\\/@");
valid = (p != NULL && p > user && p < user + strlen(user) - 1);
}
static CURLcode pubkey_pem_to_der(const char *pem,
unsigned char **der, size_t *der_len)
{
- char *begin_pos, *end_pos;
+ const char *begin_pos, *end_pos;
size_t pem_count, pem_len;
CURLcode result;
struct dynbuf pbuf;
}
}
if(hdrcbdata->config->writeout) {
- char *value = memchr(ptr, ':', cb);
+ const char *value = memchr(ptr, ':', cb);
if(value) {
if(per->was_last_header_empty)
per->num_headers = 0;
(scheme == proto_http || scheme == proto_https ||
scheme == proto_rtsp || scheme == proto_file)) {
/* bold headers only for selected protocols */
- char *value = NULL;
+ const char *value = NULL;
if(!outs->stream && !tool_create_output_file(outs, per->config))
return CURL_WRITEFUNC_ERROR;
bool negate;
const struct flagmap *map;
size_t len;
- char *next = strchr(flag, ','); /* Find next comma or end */
+ const char *next = strchr(flag, ','); /* Find next comma or end */
if(next)
len = next - flag;
else
char *path = NULL;
char *query = NULL;
if(uh) {
- char *ptr;
+ const char *ptr;
uerr = curl_url_set(uh, CURLUPART_URL, *inurlp,
CURLU_GUESS_SCHEME | CURLU_NON_SUPPORT_SCHEME);
if(uerr) {
static ParameterError varfunc(char *c, /* content */
size_t clen, /* content length */
- char *f, /* functions */
+ const char *f, /* functions */
size_t flen, /* function string length */
struct dynbuf *out)
{
ParameterError varexpand(const char *line, struct dynbuf *out, bool *replaced)
{
CURLcode result;
- char *envp;
+ const char *envp;
bool added = FALSE;
const char *input = line;
*replaced = FALSE;
char name[MAX_VAR_LEN];
size_t nlen;
size_t i;
- char *funcp;
- char *clp = strstr(envp, "}}");
+ const char *funcp;
+ const char *clp = strstr(envp, "}}");
size_t prefix;
if(!clp) {
if(value && vlen > 0) {
/* A variable might contain null bytes. Such bytes cannot be shown
using normal means, this is an error. */
- char *nb = memchr(value, '\0', vlen);
+ const char *nb = memchr(value, '\0', vlen);
if(nb) {
errorf("variable contains null byte");
return PARAM_EXPAND_ERROR;
static char doc[MAXDOCNAMELEN];
static char prot_str[5];
int prot_major, prot_minor;
- char *end = strstr(line, END_OF_HEADERS);
+ const char *end = strstr(line, END_OF_HEADERS);
logmsg("rtspd_ProcessRequest() called with testno %ld and line [%s]",
req->testno, line);
prot_str,
&prot_major,
&prot_minor) == 5) {
- char *ptr;
+ const char *ptr;
const char *pval;
curl_off_t testnum;
else if(!strncmp(doc, "test", 4)) {
/* if the hostname starts with test, the port number used in the
CONNECT line will be used as test number! */
- char *portp = strchr(doc, ':');
+ const char *portp = strchr(doc, ':');
if(portp && (*(portp + 1) != '\0') && ISDIGIT(*(portp + 1))) {
pval = portp + 1;
if(!curlx_str_number(&pval, &testnum, INT_MAX))
}
else {
char *orgcmd = NULL;
- char *cmd = NULL;
+ const char *cmd = NULL;
size_t cmdsize = 0;
int num = 0;
cmd = orgcmd;
while(cmd && cmdsize) {
- char *check;
+ const char *check;
if(!strncmp(CMD_AUTH_REQUIRED, cmd, strlen(CMD_AUTH_REQUIRED))) {
logmsg("instructed to require authorization header");
static char request[REQUEST_KEYWORD_SIZE];
int prot_major = 0;
int prot_minor = 0;
- char *end = strstr(line, end_of_headers);
+ const char *end = strstr(line, end_of_headers);
const char *pval;
curl_off_t num;
}
else if(req->testno == DOCNUMBER_NOTHING) {
- char *http;
+ const char *http;
bool fine = FALSE;
char *httppath = NULL;
size_t npath = 0; /* httppath length */
if(use_gopher) {
/* when using gopher we cannot check the request until the entire
thing has been received */
- char *ptr;
+ const char *ptr;
/* find the last slash in the line */
ptr = strrchr(line, '/');
}
else {
char *orgcmd = NULL;
- char *cmd = NULL;
+ const char *cmd = NULL;
size_t cmdsize = 0;
int num = 0;
cmd = orgcmd;
while(cmd && cmdsize) {
- char *check;
+ const char *check;
if(sscanf(cmd, "writedelay: %d", &num) == 1) {
logmsg("instructed to delay %d secs between packets", num);
req->writedelay = num;
static int validate_access(struct testcase *test,
const char *filename, unsigned short mode)
{
- char *ptr;
+ const char *ptr;
logmsg("trying to get file: %s mode %x", filename, mode);
static int verify(const char *info, const char *two)
{
/* the 'info' one has a newline appended */
- char *nl = strchr(info, '\n');
+ const char *nl = strchr(info, '\n');
if(!nl)
return 1; /* nope */
return strncmp(info, two, nl - info);