← Commit list

dbaf97e46

Rob Landley
Rob Landley
2005-09-05
SOURCE BUG Duration: 6s

Subject

Fix the warnings, and fix the following two obvious segfaults: ./busybox getopt -n one -n two woot ./busybox getopt -o one -o two woot

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/getopt.c+7 -10
@@ -306,7 +306,7 @@ static const char *shortopts="+ao:l:n:qQs:Tu";
int getopt_main(int argc, char *argv[])
{
const char *optstr = NULL;
- const char *name = NULL;
+ char *name = NULL;
int opt;
int compatible=0;
@@ -326,11 +326,13 @@ int getopt_main(int argc, char *argv[])
}
if (argv[1][0] != '-' || compatible) {
+ char *s;
+
quote=0;
- optstr=xmalloc(strlen(argv[1])+1);
- strcpy(optstr,argv[1]+strspn(argv[1],"-+"));
+ s=xmalloc(strlen(argv[1])+1);
+ strcpy(s,argv[1]+strspn(argv[1],"-+"));
argv[1]=argv[0];
- return (generate_output(argv+1,argc-1,optstr,long_options));
+ return (generate_output(argv+1,argc-1,s,long_options));
}
while ((opt=getopt_long(argc,argv,shortopts,longopts,NULL)) != EOF)
@@ -339,14 +341,12 @@ int getopt_main(int argc, char *argv[])
alternative=1;
break;
case 'o':
- free(optstr);
optstr = optarg;
break;
case 'l':
add_long_options(optarg);
break;
case 'n':
- free(name);
name = optarg;
break;
case 'q':
@@ -370,10 +370,7 @@ int getopt_main(int argc, char *argv[])
if (!optstr) {
if (optind >= argc)
bb_error_msg_and_die("missing optstring argument");
- else {
- optstr=bb_xstrdup(argv[optind]);
- optind++;
- }
+ else optstr=argv[optind++];
}
if (name)
argv[optind-1]=name;