META_MALLOC(s->str, s->bufsize, char);
assert(s->str != NULL);
- strncpy(s->str, init_str, s->length + 1);
+ memcpy(s->str, init_str, s->length + 1);
s->free_string_on_destroy = 1;
return s;
goto eanwrongtype;
break;
case ISMN:
- strncpy(buf, "9790", 4); /* this isn't for sure yet, for now
+ memcpy(buf, "9790", 4); /* this isn't for sure yet, for now
* ISMN it's only 9790 */
valid = (valid && ((rcheck = checkdig(buf, 13)) == check || magic));
break;
case ISBN:
- strncpy(buf, "978", 3);
+ memcpy(buf, "978", 3);
valid = (valid && ((rcheck = weight_checkdig(buf + 3, 10)) == check || magic));
break;
case ISSN:
- strncpy(buf + 10, "00", 2); /* append 00 as the normal issue
+ memcpy(buf + 10, "00", 2); /* append 00 as the normal issue
* publication code */
- strncpy(buf, "977", 3);
+ memcpy(buf, "977", 3);
valid = (valid && ((rcheck = weight_checkdig(buf + 3, 8)) == check || magic));
break;
case UPC:
#endif
/* Fill result with exactly MAX_MULTIBYTE_CHAR_LEN bytes */
- strncpy(result->bytes, s, MAX_MULTIBYTE_CHAR_LEN);
+ memcpy(result->bytes, s, MAX_MULTIBYTE_CHAR_LEN);
return true;
}
if (valueln != len)
memmove(param + valueln, param + len, strlen(param + len) + 1);
- strncpy(param, value, valueln);
+ memcpy(param, value, valueln);
return param + valueln;
}
if (des_setkey((char *) keybuf))
return (NULL);
}
- strncpy(output, setting, 9);
+ StrNCpy(output, setting, 10);
/*
* Double check that we weren't given a short setting. If we were, the
* salt, but we don't really care. Just make sure the output string
* doesn't have an extra NUL in it.
*/
- output[9] = '\0';
p = output + strlen(output);
}
else
/* We could try casting to string using the libxml function? */
xpath = (xmlChar *) palloc(pathsize + 9);
- strncpy((char *) xpath, "string(", 7);
+ memcpy((char *) xpath, "string(", 7);
memcpy((char *) (xpath + 7), VARDATA(xpathsupp), pathsize);
xpath[pathsize + 7] = ')';
xpath[pathsize + 8] = '\0';
if ((ofs = strstr(identLine->pg_role, "\\1")) != NULL)
{
+ int offset;
+
/* substitution of the first argument requested */
if (matches[1].rm_so < 0)
{
* plus null terminator
*/
regexp_pgrole = palloc0(strlen(identLine->pg_role) - 2 + (matches[1].rm_eo - matches[1].rm_so) + 1);
- strncpy(regexp_pgrole, identLine->pg_role, (ofs - identLine->pg_role));
- memcpy(regexp_pgrole + strlen(regexp_pgrole),
+ offset = ofs - identLine->pg_role;
+ memcpy(regexp_pgrole, identLine->pg_role, offset);
+ memcpy(regexp_pgrole + offset,
ident_user + matches[1].rm_so,
matches[1].rm_eo - matches[1].rm_so);
strcat(regexp_pgrole, ofs + 2);
*/
pgstat_setheader(&msg.m_hdr, PGSTAT_MTYPE_ARCHIVER);
msg.m_failed = failed;
- strncpy(msg.m_xlog, xlog, sizeof(msg.m_xlog));
+ StrNCpy(msg.m_xlog, xlog, sizeof(msg.m_xlog));
msg.m_timestamp = GetCurrentTimestamp();
pgstat_send(&msg, sizeof(msg));
}
strcpy(errbuf, msg);
else
{ /* truncate to fit */
- strncpy(errbuf, msg, errbuf_size - 1);
+ memcpy(errbuf, msg, errbuf_size - 1);
errbuf[errbuf_size - 1] = '\0';
}
}
/* register output plugin name with slot */
SpinLockAcquire(&slot->mutex);
- strncpy(NameStr(slot->data.plugin), plugin,
- NAMEDATALEN);
- NameStr(slot->data.plugin)[NAMEDATALEN - 1] = '\0';
+ StrNCpy(NameStr(slot->data.plugin), plugin, NAMEDATALEN);
SpinLockRelease(&slot->mutex);
/*
slot->data.persistency = persistency;
slot->data.xmin = InvalidTransactionId;
slot->effective_xmin = InvalidTransactionId;
- strncpy(NameStr(slot->data.name), name, NAMEDATALEN);
- NameStr(slot->data.name)[NAMEDATALEN - 1] = '\0';
+ StrNCpy(NameStr(slot->data.name), name, NAMEDATALEN);
slot->data.database = db_specific ? MyDatabaseId : InvalidOid;
slot->data.restart_lsn = InvalidXLogRecPtr;
day = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday);
tm->tm_wday = j2day(day);
- strncpy(str, days[tm->tm_wday], 3);
+ memcpy(str, days[tm->tm_wday], 3);
strcpy(str + 3, " ");
if (DateOrder == DATEORDER_DMY)
{
if (!n1 || !n2)
return -1;
- strncpy(NameStr(*n1), NameStr(*n2), NAMEDATALEN);
+ StrNCpy(NameStr(*n1), NameStr(*n2), NAMEDATALEN);
return 0;
}
len = endp - curname;
downname = downcase_truncate_identifier(curname, len, false);
Assert(strlen(downname) <= len);
- strncpy(curname, downname, len);
+ strncpy(curname, downname, len); /* strncpy is required here */
pfree(downname);
}
/* 'paste' milliseconds into place... */
sprintf(msbuf, ".%03d", (int) (tv.tv_usec / 1000));
- strncpy(formatted_log_time + 19, msbuf, 4);
+ memcpy(formatted_log_time + 19, msbuf, 4);
}
/*
pre = where - lines[i];
- strncpy(newline, lines[i], pre);
+ memcpy(newline, lines[i], pre);
- strcpy(newline + pre, replacement);
+ memcpy(newline + pre, replacement, replen);
strcpy(newline + pre + replen, lines[i] + pre + toklen);
}
/* Save it, just in case we need it later */
- strncpy(&AH->lookahead[0], sig, 5);
+ memcpy(&AH->lookahead[0], sig, 5);
AH->lookaheadLen = 5;
if (strncmp(sig, "PGDMP", 5) == 0)
break;
default:
/* trouble */
- strncpy(errStmt, qry, DB_MAX_ERR_STMT);
+ strncpy(errStmt, qry, DB_MAX_ERR_STMT); /* strncpy required here */
if (errStmt[DB_MAX_ERR_STMT - 1] != '\0')
{
errStmt[DB_MAX_ERR_STMT - 4] = '.';
return false;
}
- strncpy(mallocedval + strlen(mallocedval), str, slen + 1);
+ memcpy(mallocedval + strlen(mallocedval), str, slen + 1);
strcpy(mallocedval + strlen(mallocedval), ",");
ecpg_free(str);
}
return false;
}
- strncpy(mallocedval + strlen(mallocedval), str, slen + 1);
+ memcpy(mallocedval + strlen(mallocedval), str, slen + 1);
strcpy(mallocedval + strlen(mallocedval), ",");
ecpg_free(str);
}
}
/* also copy trailing '\0' */
- strncpy(mallocedval + strlen(mallocedval), str, slen + 1);
+ memcpy(mallocedval + strlen(mallocedval), str, slen + 1);
ecpg_free(str);
}
return false;
}
- strncpy(mallocedval + strlen(mallocedval), str, slen + 1);
+ memcpy(mallocedval + strlen(mallocedval), str, slen + 1);
strcpy(mallocedval + strlen(mallocedval), ",");
ecpg_free(str);
}
}
/* also copy trailing '\0' */
- strncpy(mallocedval + strlen(mallocedval), str, slen + 1);
+ memcpy(mallocedval + strlen(mallocedval), str, slen + 1);
ecpg_free(str);
}
return false;
}
- strncpy(mallocedval + strlen(mallocedval), str, slen + 1);
+ memcpy(mallocedval + strlen(mallocedval), str, slen + 1);
strcpy(mallocedval + strlen(mallocedval), ",");
ecpg_free(str);
}
}
/* also copy trailing '\0' */
- strncpy(mallocedval + strlen(mallocedval), str, slen + 1);
+ memcpy(mallocedval + strlen(mallocedval), str, slen + 1);
ecpg_free(str);
}
return false;
}
- strncpy(newcopy, *text, ptr);
+ memcpy(newcopy, *text, ptr);
strcpy(newcopy + ptr, buffer);
strcat(newcopy, (*text) +ptr + len);
{
case PGTYPES_TYPE_STRING_MALLOCED:
case PGTYPES_TYPE_STRING_CONSTANT:
- strncpy(start_pattern, replace_val.str_val,
- strlen(replace_val.str_val));
+ memcpy(start_pattern, replace_val.str_val,
+ strlen(replace_val.str_val));
if (replace_type == PGTYPES_TYPE_STRING_MALLOCED)
free(replace_val.str_val);
break;
return -1;
snprintf(t, PGTYPES_DATE_NUM_MAX_DIGITS,
"%u", replace_val.uint_val);
- strncpy(start_pattern, t, strlen(t));
+ memcpy(start_pattern, t, strlen(t));
free(t);
}
break;
return -1;
snprintf(t, PGTYPES_DATE_NUM_MAX_DIGITS,
"%02u", replace_val.uint_val);
- strncpy(start_pattern, t, strlen(t));
+ memcpy(start_pattern, t, strlen(t));
free(t);
}
break;
return -1;
snprintf(t, PGTYPES_DATE_NUM_MAX_DIGITS,
"%04u", replace_val.uint_val);
- strncpy(start_pattern, t, strlen(t));
+ memcpy(start_pattern, t, strlen(t));
free(t);
}
break;
day = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday);
tm->tm_wday = (int) ((day + date2j(2000, 1, 1) + 1) % 7);
- strncpy(str, days[tm->tm_wday], 3);
+ memcpy(str, days[tm->tm_wday], 3);
strcpy(str + 3, " ");
if (EuroDates)
if (plen > 1)
{
n = (char *) malloc(plen);
- strncpy(n, p + 1, plen - 1);
- n[plen - 1] = '\0';
+ StrNCpy(n, p + 1, plen);
replace_string(linebuf, n, "");
}
}
return "";
len = strspn(res->cmdStatus + 7, "0123456789");
- if (len > 23)
- len = 23;
- strncpy(buf, res->cmdStatus + 7, len);
+ if (len > sizeof(buf) - 1)
+ len = sizeof(buf) - 1;
+ memcpy(buf, res->cmdStatus + 7, len);
buf[len] = '\0';
return buf;
startpacket->protoVersion = htonl(conn->pversion);
+ /* strncpy is safe here: postmaster will handle full fields correctly */
strncpy(startpacket->user, conn->pguser, SM_USER);
strncpy(startpacket->database, conn->dbName, SM_DATABASE);
strncpy(startpacket->tty, conn->pgtty, SM_TTY);
/* Read the client certificate file */
if (conn->sslcert && strlen(conn->sslcert) > 0)
- strncpy(fnbuf, conn->sslcert, sizeof(fnbuf));
+ strlcpy(fnbuf, conn->sslcert, sizeof(fnbuf));
else if (have_homedir)
snprintf(fnbuf, sizeof(fnbuf), "%s/%s", homedir, USER_CERT_FILE);
else
#endif /* USE_SSL_ENGINE */
{
/* PGSSLKEY is not an engine, treat it as a filename */
- strncpy(fnbuf, conn->sslkey, sizeof(fnbuf));
+ strlcpy(fnbuf, conn->sslkey, sizeof(fnbuf));
}
}
else if (have_homedir)
* verification after the connection has been completed.
*/
if (conn->sslrootcert && strlen(conn->sslrootcert) > 0)
- strncpy(fnbuf, conn->sslrootcert, sizeof(fnbuf));
+ strlcpy(fnbuf, conn->sslrootcert, sizeof(fnbuf));
else if (have_homedir)
snprintf(fnbuf, sizeof(fnbuf), "%s/%s", homedir, ROOT_CERT_FILE);
else
if ((cvstore = SSL_CTX_get_cert_store(SSL_context)) != NULL)
{
if (conn->sslcrl && strlen(conn->sslcrl) > 0)
- strncpy(fnbuf, conn->sslcrl, sizeof(fnbuf));
+ strlcpy(fnbuf, conn->sslcrl, sizeof(fnbuf));
else if (have_homedir)
snprintf(fnbuf, sizeof(fnbuf), "%s/%s", homedir, ROOT_CRL_FILE);
else