aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-07-04 21:57:11 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-07-04 21:57:11 +0000
commit9835d47acc5ed1cdfe2be0932004c83bc7d94a81 (patch)
tree9fdaee97caf2d24c2699f6ae738f3a7195153bbd
parenta8a3b497fc05cf4a8545acd1cbd75f1ad2ab97c8 (diff)
downloadbusybox-w32-9835d47acc5ed1cdfe2be0932004c83bc7d94a81.tar.gz
busybox-w32-9835d47acc5ed1cdfe2be0932004c83bc7d94a81.tar.bz2
busybox-w32-9835d47acc5ed1cdfe2be0932004c83bc7d94a81.zip
man: fix missed NULL termination of an array
function old new delta man_main 741 721 -20
-rw-r--r--miscutils/man.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/miscutils/man.c b/miscutils/man.c
index 9ef1ef4a6..8c55ae9b9 100644
--- a/miscutils/man.c
+++ b/miscutils/man.c
@@ -75,7 +75,7 @@ int man_main(int argc ATTRIBUTE_UNUSED, char **argv)
75 char *sec_list; 75 char *sec_list;
76 char *cur_path, *cur_sect; 76 char *cur_path, *cur_sect;
77 char *line, *value; 77 char *line, *value;
78 int count_mp, alloc_mp, cur_mp; 78 int count_mp, cur_mp;
79 int opt, not_found; 79 int opt, not_found;
80 80
81 opt_complementary = "-1"; /* at least one argument */ 81 opt_complementary = "-1"; /* at least one argument */
@@ -83,8 +83,8 @@ int man_main(int argc ATTRIBUTE_UNUSED, char **argv)
83 argv += optind; 83 argv += optind;
84 84
85 sec_list = xstrdup("1:2:3:4:5:6:7:8:9"); 85 sec_list = xstrdup("1:2:3:4:5:6:7:8:9");
86 alloc_mp = 10; 86 /* Last valid man_path_list[] is [0x10] */
87 man_path_list = xmalloc(10 * sizeof(man_path_list[0])); 87 man_path_list = xzalloc(0x11 * sizeof(man_path_list[0]));
88 count_mp = 0; 88 count_mp = 0;
89 man_path_list[0] = xstrdup(getenv("MANPATH")); 89 man_path_list[0] = xstrdup(getenv("MANPATH"));
90 if (man_path_list[0]) 90 if (man_path_list[0])
@@ -109,11 +109,13 @@ int man_main(int argc ATTRIBUTE_UNUSED, char **argv)
109 if (strcmp("MANPATH", line) == 0) { 109 if (strcmp("MANPATH", line) == 0) {
110 man_path_list[count_mp] = xstrdup(value); 110 man_path_list[count_mp] = xstrdup(value);
111 count_mp++; 111 count_mp++;
112 if (alloc_mp == count_mp) { 112 /* man_path_list is NULL terminated */
113 alloc_mp += 10; 113 man_path_list[count_mp] = NULL;
114 man_path_list = xrealloc(man_path_list, alloc_mp * sizeof(man_path_list[0])); 114 if (!(count_mp & 0xf)) { /* 0x10, 0x20 etc */
115 /* so that last valid man_path_list[] is [count_mp + 0x10] */
116 man_path_list = xrealloc(man_path_list,
117 (count_mp + 0x11) * sizeof(man_path_list[0]));
115 } 118 }
116 /* thus man_path_list is always NULL terminated */
117 } 119 }
118 if (strcmp("MANSECT", line) == 0) { 120 if (strcmp("MANSECT", line) == 0) {
119 free(sec_list); 121 free(sec_list);