The current approach to filling tmpbuffer with completion candidates is confusing, with the buffer management being especially hard to reason about. That's because it doesn't copy the completion canidate into tmpbuffer, instead of copies a whole bunch of other nonsense and then runs the completion search from the middle of tmpbuffer! Change this to copy nothing but the completion candidate into tmpbuffer. Pretty much everything else in this patch is renaming to reflect the above change: s/p_tmp/tmpbuffer/ s/buf_size/sizeof(tmpbuffer)/
Showing the changes to kernel/debug (1 of 1 file). Show all
Unified · Split
| @@ -239,6 +239,7 @@ static char *kdb_read(char *buffer, size_t bufsize) · 238 unmodified lines | ||
| 239 | 239 | * and null byte */ |
| 240 | 240 | char *lastchar; |
| 241 | 241 | char *p_tmp; |
| 242 | + char tmp; | |
| 242 | 243 | static char tmpbuffer[CMD_BUFLEN]; |
| 243 | 244 | int len = strlen(buffer); |
| 244 | 245 | int len_tmp; |
| @@ -246,8 +247,7 @@ static char *kdb_read(char *buffer, size_t bufsize) · 1 unmodified line | ||
| 246 | 247 | int count; |
| 247 | 248 | int i; |
| 248 | 249 | int diag, dtab_count; |
| 249 | − int key, buf_size, ret; | |
| 250 | − | |
| 250 | + int key, ret; | |
| 251 | 251 | |
| 252 | 252 | diag = kdbgetintenv("DTABCOUNT", &dtab_count); |
| 253 | 253 | if (diag) |
| @@ -329,21 +329,16 @@ poll_again: · 75 unmodified lines | ||
| 329 | 329 | case 9: /* Tab */ |
| 330 | 330 | if (tab < 2) |
| 331 | 331 | ++tab; |
| 332 | − p_tmp = buffer; | |
| 333 | − while (*p_tmp == ' ') | |
| 334 | − p_tmp++; | |
| 335 | − if (p_tmp > cp) | |
| 336 | − break; | |
| 337 | − memcpy(tmpbuffer, p_tmp, cp-p_tmp); | |
| 338 | − *(tmpbuffer + (cp-p_tmp)) = '\0'; | |
| 339 | − p_tmp = strrchr(tmpbuffer, ' '); | |
| 340 | − if (p_tmp) | |
| 341 | − ++p_tmp; | |
| 342 | − else | |
| 343 | − p_tmp = tmpbuffer; | |
| 344 | − len = strlen(p_tmp); | |
| 345 | − buf_size = sizeof(tmpbuffer) - (p_tmp - tmpbuffer); | |
| 346 | − count = kallsyms_symbol_complete(p_tmp, buf_size); | |
| 332 | + | |
| 333 | + tmp = *cp; | |
| 334 | + *cp = '\0'; | |
| 335 | + p_tmp = strrchr(buffer, ' '); | |
| 336 | + p_tmp = (p_tmp ? p_tmp + 1 : buffer); | |
| 337 | + strscpy(tmpbuffer, p_tmp, sizeof(tmpbuffer)); | |
| 338 | + *cp = tmp; | |
| 339 | + | |
| 340 | + len = strlen(tmpbuffer); | |
| 341 | + count = kallsyms_symbol_complete(tmpbuffer, sizeof(tmpbuffer)); | |
| 347 | 342 | if (tab == 2 && count > 0) { |
| 348 | 343 | kdb_printf("\n%d symbols are found.", count); |
| 349 | 344 | if (count > dtab_count) { |
| @@ -355,14 +350,14 @@ poll_again: · 5 unmodified lines | ||
| 355 | 350 | } |
| 356 | 351 | kdb_printf("\n"); |
| 357 | 352 | for (i = 0; i < count; i++) { |
| 358 | − ret = kallsyms_symbol_next(p_tmp, i, buf_size); | |
| 353 | + ret = kallsyms_symbol_next(tmpbuffer, i, sizeof(tmpbuffer)); | |
| 359 | 354 | if (WARN_ON(!ret)) |
| 360 | 355 | break; |
| 361 | 356 | if (ret != -E2BIG) |
| 362 | − kdb_printf("%s ", p_tmp); | |
| 357 | + kdb_printf("%s ", tmpbuffer); | |
| 363 | 358 | else |
| 364 | − kdb_printf("%s... ", p_tmp); | |
| 365 | − *(p_tmp + len) = '\0'; | |
| 359 | + kdb_printf("%s... ", tmpbuffer); | |
| 360 | + tmpbuffer[len] = '\0'; | |
| 366 | 361 | } |
| 367 | 362 | if (i >= dtab_count) |
| 368 | 363 | kdb_printf("..."); |
| @@ -373,14 +368,14 @@ poll_again: · 4 unmodified lines | ||
| 373 | 368 | kdb_position_cursor(kdb_prompt_str, buffer, cp); |
| 374 | 369 | } else if (tab != 2 && count > 0) { |
| 375 | 370 | /* How many new characters do we want from tmpbuffer? */ |
| 376 | − len_tmp = strlen(p_tmp) - len; | |
| 371 | + len_tmp = strlen(tmpbuffer) - len; | |
| 377 | 372 | if (lastchar + len_tmp >= bufend) |
| 378 | 373 | len_tmp = bufend - lastchar; |
| 379 | 374 | |
| 380 | 375 | if (len_tmp) { |
| 381 | 376 | /* + 1 ensures the '\0' is memmove'd */ |
| 382 | 377 | memmove(cp+len_tmp, cp, (lastchar-cp) + 1); |
| 383 | − memcpy(cp, p_tmp+len, len_tmp); | |
| 378 | + memcpy(cp, tmpbuffer+len, len_tmp); | |
| 384 | 379 | kdb_printf("%s", cp); |
| 385 | 380 | cp += len_tmp; |
| 386 | 381 | lastchar += len_tmp; |