diff options
author | victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2004-10-10 09:11:52 +0800 |
---|---|---|
committer | victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2004-10-10 09:11:52 +0800 |
commit | ff79e173c71cc5d3df73580d24293c9da2a5151f (patch) | |
tree | 5d274a6c5c5d09262d3358bcc46e0025f95ca7d2 | |
parent | 24bd2752cd23ce5ff7d7c0612a4b6e66642694e2 (diff) | |
download | pttbbs-ff79e173c71cc5d3df73580d24293c9da2a5151f.tar pttbbs-ff79e173c71cc5d3df73580d24293c9da2a5151f.tar.gz pttbbs-ff79e173c71cc5d3df73580d24293c9da2a5151f.tar.bz2 pttbbs-ff79e173c71cc5d3df73580d24293c9da2a5151f.tar.lz pttbbs-ff79e173c71cc5d3df73580d24293c9da2a5151f.tar.xz pttbbs-ff79e173c71cc5d3df73580d24293c9da2a5151f.tar.zst pttbbs-ff79e173c71cc5d3df73580d24293c9da2a5151f.zip |
revise to proper buffer len
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@2240 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r-- | mbbsd/stuff.c | 11 | ||||
-rw-r--r-- | mbbsd/user.c | 40 |
2 files changed, 37 insertions, 14 deletions
diff --git a/mbbsd/stuff.c b/mbbsd/stuff.c index 4002f39e..8f6f65d5 100644 --- a/mbbsd/stuff.c +++ b/mbbsd/stuff.c @@ -152,6 +152,17 @@ trim(char *buf) } } +/* remove last '\n' */ +void chomp(char *src) +{ + while(*src){ + if (*src == '\n') + *src = 0; + else + src++; + } +} + /* ----------------------------------------------------- */ /* 字串檢查函數:英文、數字、檔名、E-mail address */ /* ----------------------------------------------------- */ diff --git a/mbbsd/user.c b/mbbsd/user.c index 3e811b41..0428e22d 100644 --- a/mbbsd/user.c +++ b/mbbsd/user.c @@ -1242,11 +1242,11 @@ static char *isvalidphone(char *phone) int u_register(void) { - char rname[21], addr[51], ident[11], mobile[21]; + char rname[20], addr[50], ident[11], mobile[16]; #ifdef FOREIGN_REG char fore[2]; #endif - char phone[21], career[41], email[51], birthday[9], sex_is[2], + char phone[20], career[40], email[50], birthday[9], sex_is[2], year, mon, day; char inregcode[14], regcode[50]; char ans[3], *ptr, *errcode; @@ -1285,18 +1285,30 @@ u_register(void) career[0] = phone[0] = '\0'; sethomefile(genbuf, cuser.userid, "justify.wait"); if ((fn = fopen(genbuf, "r"))) { - fgets(phone, sizeof(phone), fn); - phone[strlen(phone) - 1] = 0; - fgets(career, sizeof(career), fn); - career[strlen(career) - 1] = 0; - fgets(ident, sizeof(ident), fn); - ident[strlen(ident) - 1] = 0; - fgets(rname, sizeof(rname), fn); - rname[strlen(rname) - 1] = 0; - fgets(addr, sizeof(addr), fn); - addr[strlen(addr) - 1] = 0; - fgets(mobile, sizeof(mobile), fn); - mobile[strlen(mobile) - 1] = 0; + fgets(genbuf, sizeof(genbuf), fn); + chomp(genbuf); + strlcpy(phone, genbuf, sizeof(phone)); + + fgets(genbuf, sizeof(genbuf), fn); + chomp(genbuf); + strlcpy(career, genbuf, sizeof(career)); + + fgets(genbuf, sizeof(genbuf), fn); + chomp(genbuf); + strlcpy(ident, genbuf, sizeof(ident)); + + fgets(genbuf, sizeof(genbuf), fn); + chomp(genbuf); + strlcpy(rname, genbuf, sizeof(rname)); + + fgets(genbuf, sizeof(genbuf), fn); + chomp(genbuf); + strlcpy(addr, genbuf, sizeof(addr)); + + fgets(genbuf, sizeof(genbuf), fn); + chomp(genbuf); + strlcpy(mobile, genbuf, sizeof(mobile)); + fclose(fn); } |