← Commit list

22d3958d7

Rob Landley
Rob Landley
2006-07-11
SOURCE BUG Duration: 43s

Subject

Denis Vlasenko spotted the lack of bounds checking in my first attempt at itoa/utoa.

SOURCE BUG

This commit was genuinely broken at the time (not related to our build system): scripts/config/mkconfigs.c (2005-08-01 - 2006-10-05 arasi) uretilen bbconfigopts.h icine .config satirlarini kacissiz, ham newline'larla gömüyordu - gecerli C degildi, busybox'un kendi bb_mkdep araci bile parse edemiyordu (7d219aab7 ile duzeltildi, mkconfigs shell scripte cevrildi)

→ Bu hatanin tam hikayesini ve duzeltme diffini gor

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

libbb/xfuncs.c+14 -11
@@ -237,19 +237,21 @@ int wait4pid(int pid)
// http://www.unix.org/whitepapers/64bit.html
static char local_buf[12];
-void utoa_to_buf(unsigned n, char *buf, int buflen)
+void utoa_to_buf(unsigned n, char *buf, unsigned buflen)
{
int i, out = 0;
- for (i=1000000000; i; i/=10) {
- int res = n/i;
-
- if (res || out || i == 1) {
- out++;
- n -= res*i;
- *buf++ = '0' + res;
+ if (buflen) {
+ for (i=1000000000; i; i/=10) {
+ int res = n/i;
+
+ if ((res || out || i == 1) && --buflen>0) {
+ out++;
+ n -= res*i;
+ *buf++ = '0' + res;
+ }
}
+ *buf = 0;
}
- *buf = 0;
}
// Note: uses static buffer, calling it twice in a row will overwrite.
@@ -261,11 +263,12 @@ char *utoa(unsigned n)
return local_buf;
}
-void itoa_to_buf(int n, char *buf, int buflen)
+void itoa_to_buf(int n, char *buf, unsigned buflen)
{
- if (n<0) {
+ if (buflen && n<0) {
n = -n;
*buf++ = '-';
+ buflen--;
}
utoa_to_buf((unsigned)n, buf, buflen);
}