Integer overflow in the source code tool_cb_prg.c
The progress-bar drawing code in curl's command-line tool adds small offsets to an unsigned tick counter before taking it modulo 200, so the addition can wrap around once the counter is very large. The reporter states this only causes a cosmetic logic error in the progress display, with no significant impact.
Originally disclosed on HackerOne
- Disclosed after 20 months
Summary:
Integer overflow in the source code tool_cb_prg.c
Steps To Reproduce:
Review the source code of tool_cb_prg.c In the function fly, pay attention to Line 80, 82, 84
69 static void fly(struct ProgressData *bar, bool moved)
70 {
71 char buf[256];
72 int pos;
73 int check = bar->width - 2;
74
75 msnprintf(buf, sizeof(buf), "%*s\r", bar->width-1, " ");
76 memcpy(&buf[bar->bar], "-=O=-", 5);
77
78 pos = sinus[bar->tick%200] / (10000 / check);
79 buf[pos] = '#';
80 pos = sinus[(bar->tick + 5)%200] / (10000 / check);
81 buf[pos] = '#';
82 pos = sinus[(bar->tick + 10)%200] / (10000 / check);
83 buf[pos] = '#';
84 pos = sinus[(bar->tick + 15)%200] / (10000 / check);
85 buf[pos] = '#';
in Line 80, Line 82, Line 84, there are integer overflow issues. the type of 'tick' is 'unsigned int' bar->tick could be a large value, then bar->tick + 5 may revert to a small value. Here no big impact and only logic error.
I think maybe a logic like this is better to avoid integer overflow.
pos = sinus[((bar->tick)%200 + 5)%200] / (10000 / check);
I am not sure if I directly create this issue on github is the correct way, so I report it here.
Supporting Material/References:
[list any additional material (e.g. screenshots, logs, etc.)]
- [attachment / reference]
The output of the my self-development code scan tool: [Scanning] /home/a/Data/curl/src/tool_cb_prg.c Integer Overflow found in file: /home/a/Data/curl/src/tool_cb_prg.c, Line: 80, Column: 28 pos = sinus[(bar->tick + 5)%200] / (10000 / check); Integer Overflow found in file: /home/a/Data/curl/src/tool_cb_prg.c, Line: 82, Column: 28 pos = sinus[(bar->tick + 10)%200] / (10000 / check); Integer Overflow found in file: /home/a/Data/curl/src/tool_cb_prg.c, Line: 84, Column: 28 pos = sinus[(bar->tick + 15)%200] / (10000 / check);
Impact
This integer overflow has no big impact and only may cause business logic error.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The code adds an offset to an unsigned integer before reducing it modulo 200, so the addition can wrap when the counter is near its maximum.
Impact
The reporter says there is no big impact and it may only cause a business logic error in the progress display.
What the attacker needed
None
The fix
The reporter suggests taking the modulo of the counter first and then adding the offset before a second modulo, so the addition cannot wrap.
How it was found
- Open the source file tool_cb_prg.c and look at the fly function.
- Note the lines where an offset is added to the tick counter before the modulo operation.
- Observe that the tick counter is an unsigned integer that can grow very large, so the addition can wrap.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A program keeps a counter that grows over time, and the code adds a small number to it before using it to pick a position on screen. If the counter gets close to the largest value the number type can hold, adding to it wraps around to a tiny number instead of a big one. Here that only makes the little moving animation in the download progress bar jump to the wrong spot, so nothing dangerous happens.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.