Upgrade toybox to a51c66edb7c986337bbe69c0473265a3eac56522 am: 9e0049efd6 am: e5e09c9b54

Original change: undetermined

Change-Id: I6fdc061efb56037416e075cebfc4efd9d1a6d220
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/METADATA b/METADATA
index 013553a..567b074 100644
--- a/METADATA
+++ b/METADATA
@@ -9,12 +9,12 @@
   last_upgrade_date {
     year: 2024
     month: 11
-    day: 12
+    day: 18
   }
   homepage: "https://landley.net/toybox/"
   identifier {
     type: "Git"
     value: "https://github.com/landley/toybox"
-    version: "2045c952145e4628d0ae2011f80e7b33974cea60"
+    version: "a51c66edb7c986337bbe69c0473265a3eac56522"
   }
 }
diff --git a/android/device/generated/help.h b/android/device/generated/help.h
index 5a3945b..eb9bd27 100644
--- a/android/device/generated/help.h
+++ b/android/device/generated/help.h
@@ -610,7 +610,7 @@
 
 #define HELP_mkdir "usage: mkdir [-vp] [-m MODE] [DIR...]\n\nCreate one or more directories.\n\n-m	Set permissions of directory to mode\n-p	Make parent directories as needed\n-v	Verbose"
 
-#define HELP_ls "usage: ls [-1ACFHLNRSUXZabcdfghilmnopqrstuwx] [--color[=auto]] [FILE...]\n\nList files\n\nwhat to show:\n-A  all files except . and ..      -a  all files including .hidden\n-b  escape nongraphic chars        -d  directory, not contents\n-F  append /dir *exe @sym |FIFO    -f  files (no sort/filter/format)\n-H  follow command line symlinks   -i  inode number\n-L  follow symlinks                -N  no escaping, even on tty\n-p  put '/' after dir names        -q  unprintable chars as '?'\n-R  recursively list in subdirs    -s  storage used (in --block-size)\n-Z  security context\n\noutput formats:\n-1  list one file per line         -C  columns (sorted vertically)\n-g  like -l but no owner           -h  human readable sizes\n-k  reset --block-size to default  -l  long (show full details)\n-m  comma separated                -ll long with nanoseconds (--full-time)\n-n  long with numeric uid/gid      -o  long without group column\n-r  reverse order                  -w  set column width\n-x  columns (horizontal sort)\n\nsort by:  (also --sort=longname,longname... ends with alphabetical)\n-c  ctime      -r  reverse    -S  size     -t  time    -u  atime    -U  none\n-X  extension  -!  dirfirst   -~  nocase\n\n--block-size N	block size (default 1024, -k resets to 1024)\n--color  =always (default)  =auto (when stdout is tty) =never\n    exe=green  suid=red  suidfile=redback  stickydir=greenback\n    device=yellow  symlink=turquoise/red  dir=blue  socket=purple\n\nLong output uses -cu for display, use -ltc/-ltu to also sort by ctime/atime."
+#define HELP_ls "usage: ls [-1ACFHLNRSUXZabcdfghilmnopqrstuwx] [--color[=auto]] [FILE...]\n\nList files\n\nwhat to show:\n-A  all files except . and ..      -a  all files including .hidden\n-b  escape nongraphic chars        -d  directory, not contents\n-F  append /dir *exe @sym |FIFO    -f  files (no sort/filter/format)\n-H  follow command line symlinks   -i  inode number\n-L  follow symlinks                -N  no escaping, even on tty\n-p  put '/' after dir names        -q  unprintable chars as '?'\n-R  recursively list in subdirs    -s  storage used (units of --block-size)\n-Z  security context\n\noutput formats:\n-1  list one file per line         -C  columns (sorted vertically)\n-g  like -l but no owner           -h  human readable sizes\n-k  reset --block-size to default  -l  long (show full details)\n-m  comma separated                -ll long with nanoseconds (--full-time)\n-n  long with numeric uid/gid      -o  long without group column\n-r  reverse order                  -w  set column width\n-x  columns (horizontal sort)\n\nsort by:  (also --sort=longname,longname... ends with alphabetical)\n-c  ctime      -r  reverse    -S  size     -t  time    -u  atime    -U  none\n-X  extension  -!  dirfirst   -~  nocase\n\n--block-size N	block size for -s (default 1024, -k resets to 1024)\n--color  =always (default)  =auto (when stdout is tty) =never\n    exe=green  suid=red  suidfile=redback  stickydir=greenback\n    device=yellow  symlink=turquoise/red  dir=blue  socket=purple\n\nLong output uses -cu for display, use -ltc/-ltu to also sort by ctime/atime."
 
 #define HELP_logger "usage: logger [-s] [-t TAG] [-p [FACILITY.]PRIORITY] [MESSAGE...]\n\nLog message (or stdin) to syslog.\n\n-s	Also write message to stderr\n-t	Use TAG instead of username to identify message source\n-p	Specify PRIORITY with optional FACILITY. Default is \"user.notice\""
 
diff --git a/android/device/generated/tags.h b/android/device/generated/tags.h
index d47e3a5..8ae910e 100644
--- a/android/device/generated/tags.h
+++ b/android/device/generated/tags.h
@@ -85,7 +85,7 @@
 #define PS_RUID                          30
 #define _PS_RUID                         (1<<30)
 #define PS_RUSER                         31
-#define _PS_RUSER                        (1<<31)
+#define _PS_RUSER                        (1LL<<31)
 #define PS_GID                           32
 #define _PS_GID                          (1LL<<32)
 #define PS_GROUP                         33
diff --git a/android/linux/generated/help.h b/android/linux/generated/help.h
index 4f902ea..aa01aac 100644
--- a/android/linux/generated/help.h
+++ b/android/linux/generated/help.h
@@ -614,7 +614,7 @@
 
 #define HELP_mkdir "usage: mkdir [-vp] [-m MODE] [DIR...]\n\nCreate one or more directories.\n\n-m	Set permissions of directory to mode\n-p	Make parent directories as needed\n-v	Verbose"
 
-#define HELP_ls "usage: ls [-1ACFHLNRSUXZabcdfghilmnopqrstuwx] [--color[=auto]] [FILE...]\n\nList files\n\nwhat to show:\n-A  all files except . and ..      -a  all files including .hidden\n-b  escape nongraphic chars        -d  directory, not contents\n-F  append /dir *exe @sym |FIFO    -f  files (no sort/filter/format)\n-H  follow command line symlinks   -i  inode number\n-L  follow symlinks                -N  no escaping, even on tty\n-p  put '/' after dir names        -q  unprintable chars as '?'\n-R  recursively list in subdirs    -s  storage used (in --block-size)\n-Z  security context\n\noutput formats:\n-1  list one file per line         -C  columns (sorted vertically)\n-g  like -l but no owner           -h  human readable sizes\n-k  reset --block-size to default  -l  long (show full details)\n-m  comma separated                -ll long with nanoseconds (--full-time)\n-n  long with numeric uid/gid      -o  long without group column\n-r  reverse order                  -w  set column width\n-x  columns (horizontal sort)\n\nsort by:  (also --sort=longname,longname... ends with alphabetical)\n-c  ctime      -r  reverse    -S  size     -t  time    -u  atime    -U  none\n-X  extension  -!  dirfirst   -~  nocase\n\n--block-size N	block size (default 1024, -k resets to 1024)\n--color  =always (default)  =auto (when stdout is tty) =never\n    exe=green  suid=red  suidfile=redback  stickydir=greenback\n    device=yellow  symlink=turquoise/red  dir=blue  socket=purple\n\nLong output uses -cu for display, use -ltc/-ltu to also sort by ctime/atime."
+#define HELP_ls "usage: ls [-1ACFHLNRSUXZabcdfghilmnopqrstuwx] [--color[=auto]] [FILE...]\n\nList files\n\nwhat to show:\n-A  all files except . and ..      -a  all files including .hidden\n-b  escape nongraphic chars        -d  directory, not contents\n-F  append /dir *exe @sym |FIFO    -f  files (no sort/filter/format)\n-H  follow command line symlinks   -i  inode number\n-L  follow symlinks                -N  no escaping, even on tty\n-p  put '/' after dir names        -q  unprintable chars as '?'\n-R  recursively list in subdirs    -s  storage used (units of --block-size)\n-Z  security context\n\noutput formats:\n-1  list one file per line         -C  columns (sorted vertically)\n-g  like -l but no owner           -h  human readable sizes\n-k  reset --block-size to default  -l  long (show full details)\n-m  comma separated                -ll long with nanoseconds (--full-time)\n-n  long with numeric uid/gid      -o  long without group column\n-r  reverse order                  -w  set column width\n-x  columns (horizontal sort)\n\nsort by:  (also --sort=longname,longname... ends with alphabetical)\n-c  ctime      -r  reverse    -S  size     -t  time    -u  atime    -U  none\n-X  extension  -!  dirfirst   -~  nocase\n\n--block-size N	block size for -s (default 1024, -k resets to 1024)\n--color  =always (default)  =auto (when stdout is tty) =never\n    exe=green  suid=red  suidfile=redback  stickydir=greenback\n    device=yellow  symlink=turquoise/red  dir=blue  socket=purple\n\nLong output uses -cu for display, use -ltc/-ltu to also sort by ctime/atime."
 
 #define HELP_logger "usage: logger [-s] [-t TAG] [-p [FACILITY.]PRIORITY] [MESSAGE...]\n\nLog message (or stdin) to syslog.\n\n-s	Also write message to stderr\n-t	Use TAG instead of username to identify message source\n-p	Specify PRIORITY with optional FACILITY. Default is \"user.notice\""
 
diff --git a/android/linux/generated/tags.h b/android/linux/generated/tags.h
index d47e3a5..8ae910e 100644
--- a/android/linux/generated/tags.h
+++ b/android/linux/generated/tags.h
@@ -85,7 +85,7 @@
 #define PS_RUID                          30
 #define _PS_RUID                         (1<<30)
 #define PS_RUSER                         31
-#define _PS_RUSER                        (1<<31)
+#define _PS_RUSER                        (1LL<<31)
 #define PS_GID                           32
 #define _PS_GID                          (1LL<<32)
 #define PS_GROUP                         33
diff --git a/android/mac/generated/help.h b/android/mac/generated/help.h
index 4f902ea..aa01aac 100644
--- a/android/mac/generated/help.h
+++ b/android/mac/generated/help.h
@@ -614,7 +614,7 @@
 
 #define HELP_mkdir "usage: mkdir [-vp] [-m MODE] [DIR...]\n\nCreate one or more directories.\n\n-m	Set permissions of directory to mode\n-p	Make parent directories as needed\n-v	Verbose"
 
-#define HELP_ls "usage: ls [-1ACFHLNRSUXZabcdfghilmnopqrstuwx] [--color[=auto]] [FILE...]\n\nList files\n\nwhat to show:\n-A  all files except . and ..      -a  all files including .hidden\n-b  escape nongraphic chars        -d  directory, not contents\n-F  append /dir *exe @sym |FIFO    -f  files (no sort/filter/format)\n-H  follow command line symlinks   -i  inode number\n-L  follow symlinks                -N  no escaping, even on tty\n-p  put '/' after dir names        -q  unprintable chars as '?'\n-R  recursively list in subdirs    -s  storage used (in --block-size)\n-Z  security context\n\noutput formats:\n-1  list one file per line         -C  columns (sorted vertically)\n-g  like -l but no owner           -h  human readable sizes\n-k  reset --block-size to default  -l  long (show full details)\n-m  comma separated                -ll long with nanoseconds (--full-time)\n-n  long with numeric uid/gid      -o  long without group column\n-r  reverse order                  -w  set column width\n-x  columns (horizontal sort)\n\nsort by:  (also --sort=longname,longname... ends with alphabetical)\n-c  ctime      -r  reverse    -S  size     -t  time    -u  atime    -U  none\n-X  extension  -!  dirfirst   -~  nocase\n\n--block-size N	block size (default 1024, -k resets to 1024)\n--color  =always (default)  =auto (when stdout is tty) =never\n    exe=green  suid=red  suidfile=redback  stickydir=greenback\n    device=yellow  symlink=turquoise/red  dir=blue  socket=purple\n\nLong output uses -cu for display, use -ltc/-ltu to also sort by ctime/atime."
+#define HELP_ls "usage: ls [-1ACFHLNRSUXZabcdfghilmnopqrstuwx] [--color[=auto]] [FILE...]\n\nList files\n\nwhat to show:\n-A  all files except . and ..      -a  all files including .hidden\n-b  escape nongraphic chars        -d  directory, not contents\n-F  append /dir *exe @sym |FIFO    -f  files (no sort/filter/format)\n-H  follow command line symlinks   -i  inode number\n-L  follow symlinks                -N  no escaping, even on tty\n-p  put '/' after dir names        -q  unprintable chars as '?'\n-R  recursively list in subdirs    -s  storage used (units of --block-size)\n-Z  security context\n\noutput formats:\n-1  list one file per line         -C  columns (sorted vertically)\n-g  like -l but no owner           -h  human readable sizes\n-k  reset --block-size to default  -l  long (show full details)\n-m  comma separated                -ll long with nanoseconds (--full-time)\n-n  long with numeric uid/gid      -o  long without group column\n-r  reverse order                  -w  set column width\n-x  columns (horizontal sort)\n\nsort by:  (also --sort=longname,longname... ends with alphabetical)\n-c  ctime      -r  reverse    -S  size     -t  time    -u  atime    -U  none\n-X  extension  -!  dirfirst   -~  nocase\n\n--block-size N	block size for -s (default 1024, -k resets to 1024)\n--color  =always (default)  =auto (when stdout is tty) =never\n    exe=green  suid=red  suidfile=redback  stickydir=greenback\n    device=yellow  symlink=turquoise/red  dir=blue  socket=purple\n\nLong output uses -cu for display, use -ltc/-ltu to also sort by ctime/atime."
 
 #define HELP_logger "usage: logger [-s] [-t TAG] [-p [FACILITY.]PRIORITY] [MESSAGE...]\n\nLog message (or stdin) to syslog.\n\n-s	Also write message to stderr\n-t	Use TAG instead of username to identify message source\n-p	Specify PRIORITY with optional FACILITY. Default is \"user.notice\""
 
diff --git a/android/mac/generated/tags.h b/android/mac/generated/tags.h
index d47e3a5..8ae910e 100644
--- a/android/mac/generated/tags.h
+++ b/android/mac/generated/tags.h
@@ -85,7 +85,7 @@
 #define PS_RUID                          30
 #define _PS_RUID                         (1<<30)
 #define PS_RUSER                         31
-#define _PS_RUSER                        (1<<31)
+#define _PS_RUSER                        (1LL<<31)
 #define PS_GID                           32
 #define _PS_GID                          (1LL<<32)
 #define PS_GROUP                         33
diff --git a/scripts/make.sh b/scripts/make.sh
index ff677d5..3f4b307 100755
--- a/scripts/make.sh
+++ b/scripts/make.sh
@@ -218,7 +218,7 @@
 while read i; do
   [ "$i" = "${i#_}" ] && { HEAD="$i"; X=0; LL=; continue;}
   for j in $i; do
-    [ $X -eq 32 ] && LL=LL
+    [ $X -eq 31 ] && LL=LL
     NAME="$HEAD$j"
     printf "#define $NAME %*s%s\n#define _$NAME %*s%s\n" \
       $((32-${#NAME})) "" "$X" $((31-${#NAME})) "" "(1$LL<<$((X++)))" || exit 1
diff --git a/toys/net/host.c b/toys/net/host.c
index 1d06159..6ead028 100644
--- a/toys/net/host.c
+++ b/toys/net/host.c
@@ -105,7 +105,7 @@
     }
     if (i == ARRAY_LEN(rrt)) error_exit("bad -t: %s", TT.t);
   }
-  qlen = res_mkquery(0, name, 1, type, 0, 0, 0, t2, 280); //t2len);
+  qlen = res_mkquery(0, name, 1, type, 0, 0, 0, t2, t2len);
   if (qlen<0) error_exit("bad NAME: %s", name);
 
   // Grab nameservers
@@ -122,9 +122,10 @@
     setsockopt(i, SOL_SOCKET, SO_RCVTIMEO, &(struct timeval){ .tv_sec = 5 },
       sizeof(struct timeval));
     send(i, t2, qlen, 0);
-    if (16 < (alen = recv(i, abuf, abuf_len, 0))) break;
-    if (!*++TT.nsname) error_exit("Host not found.");
+    alen = recv(i, abuf, abuf_len, 0);
     close(i);
+    if (16<alen) break;
+    if (!*++TT.nsname) error_exit("Host not found.");
   }
 
   // Did it error?
@@ -136,19 +137,20 @@
   if (rcode) error_exit("Host not found: %s",
     (char *[]){ "Format error", "Server failure",
     "Non-existant domain", "Not implemented", "Refused", ""}[rcode-1]);
+  if (abuf[2]&2) puts("Truncated");
 
   // Print the result
   p = abuf + 12;
   qlen = 0;
   for (sec = 0; sec<(2<<verbose); sec++) {
     count = peek_be(abuf+4+2*sec, 2);
-    if (verbose && count>0 && sec>1)
+    if (verbose && count && sec>1)
       puts(sec==2 ? "For authoritative answers, see:"
         : "Additional information:");
 
     for (; count--; p += pllen) {
-      p += xdn_expand(abuf, abuf+alen, p, toybuf, 4096-t2len);
-      if (alen-(p-abuf)<10) error_exit("tilt");
+      p += xdn_expand(abuf, abuf+alen, p, toybuf, sizeof(toybuf)-t2len);
+      if (alen-(p-abuf)<10) error_exit("bad header");
       type = peek_be(p, 2);
       p += 4;
       if (!sec) continue;
@@ -156,13 +158,14 @@
       p += 4;
       pllen = peek_be(p, 2);
       p += 2;
-      if ((p-abuf)+pllen>alen) error_exit("tilt");
+      if ((p-abuf)+pllen>alen) error_exit("bad header");
       if (type==1 || type == 28)
         inet_ntop(type==1 ? AF_INET : AF_INET6, p, t2, t2len);
       else if (type==2 || type==5) xdn_expand(abuf, abuf+alen, p, t2, t2len);
-      else if (type==13 || type==16)
+      else if (type==13 || type==16) {
+        if (pllen && pllen-1==*p) p++, pllen--;
         sprintf(t2, "\"%.*s\"", minof(pllen, t2len), p);
-      else if (type==6) {
+      } else if (type==6) {
         ss = p+xdn_expand(abuf, abuf+alen, p, t2, t2len-1);
         j = strlen(t2);
         t2[j++] = ' ';
diff --git a/toys/posix/ls.c b/toys/posix/ls.c
index 3addd45..7a8dfd2 100644
--- a/toys/posix/ls.c
+++ b/toys/posix/ls.c
@@ -30,7 +30,7 @@
     -H  follow command line symlinks   -i  inode number
     -L  follow symlinks                -N  no escaping, even on tty
     -p  put '/' after dir names        -q  unprintable chars as '?'
-    -R  recursively list in subdirs    -s  storage used (in --block-size)
+    -R  recursively list in subdirs    -s  storage used (units of --block-size)
     -Z  security context
 
     output formats:
@@ -46,7 +46,7 @@
     -c  ctime      -r  reverse    -S  size     -t  time    -u  atime    -U  none
     -X  extension  -!  dirfirst   -~  nocase
 
-    --block-size N	block size (default 1024, -k resets to 1024)
+    --block-size N	block size for -s (default 1024, -k resets to 1024)
     --color  =always (default)  =auto (when stdout is tty) =never
         exe=green  suid=red  suidfile=redback  stickydir=greenback
         device=yellow  symlink=turquoise/red  dir=blue  socket=purple