fixing (?) the strncpy bug
This commit is contained in:
parent
791f3b1327
commit
198b54d316
4
ex17.c
4
ex17.c
@ -107,13 +107,13 @@ void Database_set(struct Connection *conn, int id, const char *name, const char
|
|||||||
if(addr->set) die("Already set, delete it first");
|
if(addr->set) die("Already set, delete it first");
|
||||||
|
|
||||||
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) die("Name copy failed");
|
if(!res) 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) die("Email copy failed");
|
if(!res) 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