comparison svr-runopts.c @ 1173:d734fe76b72f coverity

merge
author Matt Johnston <matt@ucc.asn.au>
date Mon, 23 Nov 2015 23:04:48 +0800
parents 8b6cba298768
children 424822a6f8ee
comparison
equal deleted inserted replaced
1144:624fc24cfae5 1173:d734fe76b72f
110 DEFAULT_RECV_WINDOW, DEFAULT_KEEPALIVE, DEFAULT_IDLE_TIMEOUT); 110 DEFAULT_RECV_WINDOW, DEFAULT_KEEPALIVE, DEFAULT_IDLE_TIMEOUT);
111 } 111 }
112 112
113 void svr_getopts(int argc, char ** argv) { 113 void svr_getopts(int argc, char ** argv) {
114 114
115 unsigned int i; 115 unsigned int i, j;
116 char ** next = 0; 116 char ** next = 0;
117 int nextisport = 0; 117 int nextisport = 0;
118 char* recv_window_arg = NULL; 118 char* recv_window_arg = NULL;
119 char* keepalive_arg = NULL; 119 char* keepalive_arg = NULL;
120 char* idle_timeout_arg = NULL; 120 char* idle_timeout_arg = NULL;
121 char* keyfile = NULL; 121 char* keyfile = NULL;
122 char c;
122 123
123 124
124 /* see printhelp() for options */ 125 /* see printhelp() for options */
125 svr_opts.bannerfile = NULL; 126 svr_opts.bannerfile = NULL;
126 svr_opts.banner = NULL; 127 svr_opts.banner = NULL;
166 #ifdef ENABLE_SVR_REMOTETCPFWD 167 #ifdef ENABLE_SVR_REMOTETCPFWD
167 opts.listen_fwd_all = 0; 168 opts.listen_fwd_all = 0;
168 #endif 169 #endif
169 170
170 for (i = 1; i < (unsigned int)argc; i++) { 171 for (i = 1; i < (unsigned int)argc; i++) {
171 if (nextisport) { 172 if (argv[i][0] != '-' || argv[i][1] == '\0')
172 addportandaddress(argv[i]); 173 dropbear_exit("Invalid argument: %s", argv[i]);
173 nextisport = 0; 174
174 continue; 175 for (j = 1; (c = argv[i][j]) != '\0' && !next && !nextisport; j++) {
175 } 176 switch (c) {
176
177 if (next) {
178 *next = argv[i];
179 if (*next == NULL) {
180 dropbear_exit("Invalid null argument");
181 }
182 next = 0x00;
183
184 if (keyfile) {
185 addhostkey(keyfile);
186 keyfile = NULL;
187 }
188 continue;
189 }
190
191 if (argv[i][0] == '-') {
192 switch (argv[i][1]) {
193 case 'b': 177 case 'b':
194 next = &svr_opts.bannerfile; 178 next = &svr_opts.bannerfile;
195 break; 179 break;
196 case 'd': 180 case 'd':
197 case 'r': 181 case 'r':
276 case 'V': 260 case 'V':
277 print_version(); 261 print_version();
278 exit(EXIT_SUCCESS); 262 exit(EXIT_SUCCESS);
279 break; 263 break;
280 default: 264 default:
281 fprintf(stderr, "Unknown argument %s\n", argv[i]); 265 fprintf(stderr, "Invalid option -%c\n", c);
282 printhelp(argv[0]); 266 printhelp(argv[0]);
283 exit(EXIT_FAILURE); 267 exit(EXIT_FAILURE);
284 break; 268 break;
269 }
270 }
271
272 if (!next && !nextisport)
273 continue;
274
275 if (c == '\0') {
276 i++;
277 j = 0;
278 if (!argv[i]) {
279 dropbear_exit("Missing argument");
280 }
281 }
282
283 if (nextisport) {
284 addportandaddress(&argv[i][j]);
285 nextisport = 0;
286 } else if (next) {
287 *next = &argv[i][j];
288 if (*next == NULL) {
289 dropbear_exit("Invalid null argument");
290 }
291 next = 0x00;
292
293 if (keyfile) {
294 addhostkey(keyfile);
295 keyfile = NULL;
285 } 296 }
286 } 297 }
287 } 298 }
288 299
289 /* Set up listening ports */ 300 /* Set up listening ports */