void Database_set(struct Connection *conn, int id, const char *name, const char *email){struct Address *addr = &conn->db->rows[id];if(addr->set) die("Already set, delete it first");addr->set = 1;// WARNING: bug, read the "How To Break It" and fix thischar *res = strncpy(addr->name, name, MAX_DATA);// demonstrate the strncpy bugif(!res) die("Name copy failed");res = strncpy(addr->email, email, MAX_DATA);if(!res) die("Email copy failed");}
這段程序為什么會出現(xiàn)bug?strncpy應怎么修改才行?謝謝。
ibeautiful
2023-03-05 11:07:14