← Commit list

15fe2e11d

Rob Landley
Rob Landley
2006-05-08
SOURCE BUG Duration: 70s

Subject

Shrink the code about 50 bytes, allocate less run-time memory, and add a comment that null terminating the string we sscanf() shouldn't be required since the kernel adds \n to the end of it and sscanf will stop there.

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 →

util-linux/mdev.c+19 -20
@@ -38,23 +38,25 @@ static void make_device(char *path)
int mode = 0660;
uid_t uid = 0;
gid_t gid = 0;
+ char *temp = path + strlen(path);
- RESERVE_CONFIG_BUFFER(temp, PATH_MAX);
+ /* Try to read major/minor string. Note that the kernel puts \n after
+ * the data, so we don't need to worry about null terminating the string
+ * because sscanf() will stop at the first nondigit, which \n is. We
+ * also depend on path having writeable space after it. */
- /* Try to read major/minor string */
-
- snprintf(temp, PATH_MAX, "%s/dev", path);
- fd = open(temp, O_RDONLY);
- len = read(fd, temp, PATH_MAX-1);
+ strcat(path, "/dev");
+ fd = open(path, O_RDONLY);
+ len = read(fd, temp + 1, 64);
+ *temp++ = 0;
close(fd);
- if (len < 1) goto end;
+ if (len < 1) return;
/* Determine device name, type, major and minor */
device_name = strrchr(path, '/') + 1;
- type = strncmp(path+5, "block/", 6) ? S_IFCHR : S_IFBLK;
- if (sscanf(temp, "%d:%d", &major, &minor) != 2)
- goto end;
+ type = path[5]=='c' ? S_IFCHR : S_IFBLK;
+ if (sscanf(temp, "%d:%d", &major, &minor) != 2) return;
/* If we have a config file, look up permissions for this device */
@@ -167,18 +169,14 @@ found_device:
}
}
- sprintf(temp, "%s/%s", DEV_PATH, device_name);
umask(0);
- if (mknod(temp, mode | type, makedev(major, minor)) && errno != EEXIST)
- bb_perror_msg_and_die("mknod %s failed", temp);
+ if (mknod(device_name, mode | type, makedev(major, minor)) && errno != EEXIST)
+ bb_perror_msg_and_die("mknod %s failed", device_name);
if (major==root_major && minor==root_minor)
- symlink(temp,DEV_PATH "/root");
+ symlink(device_name, "root");
- if (ENABLE_FEATURE_MDEV_CONF) chown(temp,uid,gid);
-
-end:
- RELEASE_CONFIG_BUFFER(temp);
+ if (ENABLE_FEATURE_MDEV_CONF) chown(device_name, uid, gid);
}
/* Recursive search of /sys/block or /sys/class. path must be a writeable
@@ -220,6 +218,8 @@ int mdev_main(int argc, char *argv[])
char *env_path;
RESERVE_CONFIG_BUFFER(temp,PATH_MAX);
+ bb_xchdir(DEV_PATH);
+
/* Scan */
if (argc == 2 && !strcmp(argv[1],"-s")) {
@@ -245,8 +245,7 @@ int mdev_main(int argc, char *argv[])
sprintf(temp, "/sys%s", env_path);
make_device(temp);
} else if (!strcmp(action, "remove")) {
- sprintf(temp, "%s/%s", DEV_PATH, strrchr(env_path, '/') + 1);
- unlink(temp);
+ unlink(strrchr(env_path, '/') + 1);
}
}