PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, November 15, 2022

[FIXED] Why did my alphabet had 40 letters? Or why dropping STDERR is not always a good idea

 November 15, 2022     bash, error-handling     No comments   

Issue

for ((i=000;i<040;i++));do ...

From 0 to 39, there is 40 values!? ... for printing from A to Z???

for ((i=000;i<040;i++));do
    echo -e $(eval "printf "\\\\%04o" $((65+0$i)) ");
  done 2>/dev/null |
  xargs
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

strange!?

There is 85 values, from 70 to 154:

for ((i=0070;i<0155;i++));do
    echo -e $(eval "printf "\\\\%04o" $((19+0$i)) ");
  done 2>/dev/null |
    xargs
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Complete answer wanted, explaining 𝒂𝒍𝒍 missing values.

:-p

My full answer

As this question was closed, no answer could be added, so there is my explanation:

The missunderstanding is done by the (ab)use of 2>/dev/null!!

So, simply dropping this will output:

for ((i=000;i<040;i++));do
    echo -e $(eval "printf "\\\\%04o" $((65+0$i)) ")
done  |   xargs
bash: 65+08: value too great for base (error token is "08")
bash: 65+09: value too great for base (error token is "09")
bash: 65+018: value too great for base (error token is "018")
bash: 65+019: value too great for base (error token is "019")
bash: 65+028: value too great for base (error token is "028")
bash: 65+029: value too great for base (error token is "029")
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Things become more clear!

for ((i=000;i<040;i++));do
    echo -e $(eval "printf "\\\\%04o" $((65+0$i)) ")
done 2> >(wc -l >&2) |   xargs
6
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

There are 6 error lines, because of illegal 8 or 9 digit in octal numbers.

So if this is octal, then you could either

printf %d\\n 040

or

echo $(( 040 ))

to convert 040 octal to 32 decimal. Then 32 operation with 6 errors, there are really 26 outputs.

for ((i=0070;i<0155;i++));do
    echo -e $(eval "printf "\\\\%04o" $((19+0$i)) ")
  done 2> >(wc -l >&2) | xargs 
27
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

There is in fact 27 errors, with values from... 56 to 108:

printf "%d\n" 0070 0155
56
109

There is not 85 values, but 53:

echo $(( 155 - 70 ))  $(( 0155 - 0070 ))  $(( 109 - 56 ))
85 53 53

Again: 53 operations with 27 errors = 26 outputs

echo $((53-27))
26

Yes!

This is the right number of letters (in my alphabet)!

Conclusion

The question could be rewritten as:

How abuse of /dev/null could make strange behaviours

So be carefull when redirecting STDERR! Avoid simply redirecting STDERR to /dev/null:

command 2>/dev/null

And prefer to use commands like:

command 2> >(grep -v "unwanted message" >&2)

Solution

You are simply using octal numbers, as your numbers are prefixed by 0.

So it's base 8, not base 10.



Answered By - Macmade
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing