From 198b54d316aa944ddb1033c4a9b6026a9f23b4b2 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Wed, 21 Sep 2011 22:23:37 -0400 Subject: [PATCH] fixing (?) the strncpy bug --- ex17.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ex17.c b/ex17.c index 493d9a1..19289e7 100644 --- a/ex17.c +++ b/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"); addr->set = 1; - // WARNING: bug, read the "How To Break It" and fix this char *res = strncpy(addr->name, name, MAX_DATA); - // demonstrate the strncpy bug if(!res) die("Name copy failed"); + addr->name[MAX_DATA - 1] = '\0'; res = strncpy(addr->email, email, MAX_DATA); if(!res) die("Email copy failed"); + addr->email[MAX_DATA - 1] = '\0'; } void Database_get(struct Connection *conn, int id)