Doing nully things with strncpy
This commit is contained in:
parent
1a0ba35f7a
commit
0d19b4cb4f
@ -1,2 +1,2 @@
|
|||||||
ex17.db
|
ex17.db
|
||||||
c
|
l
|
||||||
|
@ -125,17 +125,20 @@ void Database_set(struct Connection *conn, int id, const char *name, const char
|
|||||||
}
|
}
|
||||||
|
|
||||||
addr->set = 1;
|
addr->set = 1;
|
||||||
// WARNING: bug, read the "How To Break It" and fix this
|
|
||||||
char *res = strncpy(addr->name, name, MAX_DATA);
|
char *res = strncpy(addr->name, name, MAX_DATA);
|
||||||
// demonstrate the strncpy bug
|
|
||||||
if (!res) {
|
if (!res) {
|
||||||
die("Name copy failed");
|
die("Name copy failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addr->name[MAX_DATA - 1] = '\0';
|
||||||
|
|
||||||
res = strncpy(addr->email, email, MAX_DATA);
|
res = strncpy(addr->email, email, MAX_DATA);
|
||||||
if (!res) {
|
if (!res) {
|
||||||
die("Email copy failed");
|
die("Email copy failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addr->email[MAX_DATA - 1] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
void Database_get(struct Connection *conn, int id)
|
void Database_get(struct Connection *conn, int id)
|
||||||
|
Loading…
Reference in New Issue
Block a user