mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-09-01 06:55:30 +00:00
Silence "may be truncated" warnings
Use memccpy() instead of strncpy() for safe string manipulation.
This commit is contained in:
@@ -353,7 +353,6 @@ doswitch(const char *name, const char *function, const char *args,
|
|||||||
static void
|
static void
|
||||||
insert_into_typenames(int type, const char *typebuf, const char *attr) {
|
insert_into_typenames(int type, const char *typebuf, const char *attr) {
|
||||||
struct ttnam *ttn = NULL;
|
struct ttnam *ttn = NULL;
|
||||||
size_t c;
|
|
||||||
int i, n;
|
int i, n;
|
||||||
char tmp[256];
|
char tmp[256];
|
||||||
|
|
||||||
@@ -379,25 +378,25 @@ insert_into_typenames(int type, const char *typebuf, const char *attr) {
|
|||||||
ttnam_count = i + 1;
|
ttnam_count = i + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* XXXMUKS: This is redundant due to the INSIST above. */
|
char *end = memccpy(ttn->typebuf, typebuf, '\0', sizeof(ttn->typebuf));
|
||||||
if (strlen(typebuf) > sizeof(ttn->typebuf) - 1) {
|
|
||||||
|
if (end == NULL) {
|
||||||
fprintf(stderr, "Error: type name %s is too long\n", typebuf);
|
fprintf(stderr, "Error: type name %s is too long\n", typebuf);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
strncpy(ttn->typebuf, typebuf, sizeof(ttn->typebuf));
|
end = memccpy(ttn->macroname, typebuf, '\0', sizeof(ttn->macroname));
|
||||||
ttn->typebuf[sizeof(ttn->typebuf) - 1] = '\0';
|
if (end == NULL) {
|
||||||
|
fprintf(stderr, "Error: type name %s is too long\n", typebuf);
|
||||||
strncpy(ttn->macroname, ttn->typebuf, sizeof(ttn->macroname));
|
exit(EXIT_FAILURE);
|
||||||
ttn->macroname[sizeof(ttn->macroname) - 1] = '\0';
|
}
|
||||||
|
|
||||||
ttn->type = type;
|
ttn->type = type;
|
||||||
c = strlen(ttn->macroname);
|
while (end > ttn->macroname) {
|
||||||
while (c > 0) {
|
if (*end == '-') {
|
||||||
if (ttn->macroname[c - 1] == '-') {
|
*end = '_';
|
||||||
ttn->macroname[c - 1] = '_';
|
|
||||||
}
|
}
|
||||||
c--;
|
end--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (attr == NULL) {
|
if (attr == NULL) {
|
||||||
@@ -435,6 +434,7 @@ add(unsigned int rdclass, const char *classbuf, int type, const char *typebuf,
|
|||||||
struct tt *tt, *oldtt;
|
struct tt *tt, *oldtt;
|
||||||
struct cc *newcc;
|
struct cc *newcc;
|
||||||
struct cc *cc, *oldcc;
|
struct cc *cc, *oldcc;
|
||||||
|
char *end = NULL;
|
||||||
|
|
||||||
INSIST(strlen(typebuf) < TYPECLASSBUF);
|
INSIST(strlen(typebuf) < TYPECLASSBUF);
|
||||||
INSIST(strlen(classbuf) < TYPECLASSBUF);
|
INSIST(strlen(classbuf) < TYPECLASSBUF);
|
||||||
@@ -451,17 +451,17 @@ add(unsigned int rdclass, const char *classbuf, int type, const char *typebuf,
|
|||||||
newtt->rdclass = rdclass;
|
newtt->rdclass = rdclass;
|
||||||
newtt->type = type;
|
newtt->type = type;
|
||||||
|
|
||||||
strncpy(newtt->classbuf, classbuf, sizeof(newtt->classbuf));
|
end = memccpy(newtt->classbuf, classbuf, '\0', sizeof(newtt->classbuf));
|
||||||
newtt->classbuf[sizeof(newtt->classbuf) - 1] = '\0';
|
INSIST(end != NULL);
|
||||||
|
|
||||||
strncpy(newtt->typebuf, typebuf, sizeof(newtt->typebuf));
|
end = memccpy(newtt->typebuf, typebuf, '\0', sizeof(newtt->typebuf));
|
||||||
newtt->typebuf[sizeof(newtt->typebuf) - 1] = '\0';
|
INSIST(end != NULL);
|
||||||
|
|
||||||
if (strncmp(dirbuf, "./", 2) == 0) {
|
if (strncmp(dirbuf, "./", 2) == 0) {
|
||||||
dirbuf += 2;
|
dirbuf += 2;
|
||||||
}
|
}
|
||||||
strncpy(newtt->dirbuf, dirbuf, sizeof(newtt->dirbuf));
|
end = memccpy(newtt->dirbuf, dirbuf, '\0', sizeof(newtt->dirbuf));
|
||||||
newtt->dirbuf[sizeof(newtt->dirbuf) - 1] = '\0';
|
INSIST(end != NULL);
|
||||||
|
|
||||||
tt = types;
|
tt = types;
|
||||||
oldtt = NULL;
|
oldtt = NULL;
|
||||||
|
Reference in New Issue
Block a user