Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. String in hands of dumb****s

String in hands of dumb****s

Scheduled Pinned Locked Moved The Weird and The Wonderful
databaseoraclecomsaleshelp
7 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Cristian Amarie
    wrote on last edited by
    #1

    So, yesterday I received a bug " Explain SQL sometimes (!) does not work on Oracle." Twist, test, try, WTF of course. The mistery: Format of a string class (almost any). So here's how (with comments, bells, and COM follies):

    String strDest; // target for a some kind of "-u<user> -p<password>..." or so called packed args
    String strUser; // empty

    strDest.Format(_T("-u%s"), strUser);

    Unfortunately, Format call replaces "%s" with "(null)" when a null argument is passed as string. So the poor receiver attempted to decode the "-u(null)" into an user name, and he gets "(null)". Then the string horror (of course yet again not validated and unpacked without any defense) was passed to yet another string statement, so it ended up in "ALTER SESSION SET CURRENT_SCHEMA = (null)" Obviously a valid string, but probably the customer does not have an user called "(null)". I hope.

    Nuclear launch detected

    //

    M K L 3 Replies Last reply
    0
    • C Cristian Amarie

      So, yesterday I received a bug " Explain SQL sometimes (!) does not work on Oracle." Twist, test, try, WTF of course. The mistery: Format of a string class (almost any). So here's how (with comments, bells, and COM follies):

      String strDest; // target for a some kind of "-u<user> -p<password>..." or so called packed args
      String strUser; // empty

      strDest.Format(_T("-u%s"), strUser);

      Unfortunately, Format call replaces "%s" with "(null)" when a null argument is passed as string. So the poor receiver attempted to decode the "-u(null)" into an user name, and he gets "(null)". Then the string horror (of course yet again not validated and unpacked without any defense) was passed to yet another string statement, so it ended up in "ALTER SESSION SET CURRENT_SCHEMA = (null)" Obviously a valid string, but probably the customer does not have an user called "(null)". I hope.

      Nuclear launch detected

      //

      M Offline
      M Offline
      maz2331
      wrote on last edited by
      #2

      That's why I like to verify all input before passing it on. A couple "if" constructs looking for NULLs and such isn't a bad thing to throw in from time to time. if (strUser !="") { strDest.Format(_T("-u%s"), strUser); } else { // Add code to complain here } Checking for "stupid user tricks" is half the battle of coding! I tend to be very paranoid about anything "editable" by users, and check the bejezzus out of it before passing it along.

      K L 2 Replies Last reply
      0
      • M maz2331

        That's why I like to verify all input before passing it on. A couple "if" constructs looking for NULLs and such isn't a bad thing to throw in from time to time. if (strUser !="") { strDest.Format(_T("-u%s"), strUser); } else { // Add code to complain here } Checking for "stupid user tricks" is half the battle of coding! I tend to be very paranoid about anything "editable" by users, and check the bejezzus out of it before passing it along.

        K Offline
        K Offline
        KarstenK
        wrote on last edited by
        #3

        I like checking all input also X| these thumb users always want to hurd me... :doh:

        Greetings from Germany

        1 Reply Last reply
        0
        • C Cristian Amarie

          So, yesterday I received a bug " Explain SQL sometimes (!) does not work on Oracle." Twist, test, try, WTF of course. The mistery: Format of a string class (almost any). So here's how (with comments, bells, and COM follies):

          String strDest; // target for a some kind of "-u<user> -p<password>..." or so called packed args
          String strUser; // empty

          strDest.Format(_T("-u%s"), strUser);

          Unfortunately, Format call replaces "%s" with "(null)" when a null argument is passed as string. So the poor receiver attempted to decode the "-u(null)" into an user name, and he gets "(null)". Then the string horror (of course yet again not validated and unpacked without any defense) was passed to yet another string statement, so it ended up in "ALTER SESSION SET CURRENT_SCHEMA = (null)" Obviously a valid string, but probably the customer does not have an user called "(null)". I hope.

          Nuclear launch detected

          //

          K Offline
          K Offline
          Kochise
          wrote on last edited by
          #4

          String in my hands, pleases we-mean : String MyHands = new String("Please who-men"); Kochise PS : Find the "bugs" in my string or my hands...

          In Code we trust !

          1 Reply Last reply
          0
          • M maz2331

            That's why I like to verify all input before passing it on. A couple "if" constructs looking for NULLs and such isn't a bad thing to throw in from time to time. if (strUser !="") { strDest.Format(_T("-u%s"), strUser); } else { // Add code to complain here } Checking for "stupid user tricks" is half the battle of coding! I tend to be very paranoid about anything "editable" by users, and check the bejezzus out of it before passing it along.

            L Offline
            L Offline
            Leon Segal
            wrote on last edited by
            #5

            Your check would still not catch the NULL value. A much better way to validate all strings would be: if (String.IsNullOrEmpty(strUser)){ throw new ArgumentNullException(strUser); } else { strDest.Format(... } Hope this helps. .leON.

            M 1 Reply Last reply
            0
            • L Leon Segal

              Your check would still not catch the NULL value. A much better way to validate all strings would be: if (String.IsNullOrEmpty(strUser)){ throw new ArgumentNullException(strUser); } else { strDest.Format(... } Hope this helps. .leON.

              M Offline
              M Offline
              maz2331
              wrote on last edited by
              #6

              Yep - it's a better check, assuming one is working in C# or with .NET. Personally, I tend to do most of my development in C or C++ without ever touching any .NET stuff, and tend to fall into that pattern instead. It's the nature of my apps being low-level stuff for the most part that drives this, plus I like working with pointers!

              1 Reply Last reply
              0
              • C Cristian Amarie

                So, yesterday I received a bug " Explain SQL sometimes (!) does not work on Oracle." Twist, test, try, WTF of course. The mistery: Format of a string class (almost any). So here's how (with comments, bells, and COM follies):

                String strDest; // target for a some kind of "-u<user> -p<password>..." or so called packed args
                String strUser; // empty

                strDest.Format(_T("-u%s"), strUser);

                Unfortunately, Format call replaces "%s" with "(null)" when a null argument is passed as string. So the poor receiver attempted to decode the "-u(null)" into an user name, and he gets "(null)". Then the string horror (of course yet again not validated and unpacked without any defense) was passed to yet another string statement, so it ended up in "ALTER SESSION SET CURRENT_SCHEMA = (null)" Obviously a valid string, but probably the customer does not have an user called "(null)". I hope.

                Nuclear launch detected

                //

                L Offline
                L Offline
                Lutoslaw
                wrote on last edited by
                #7

                First time I saw this post I quickly searched Wikipedia what is a "WTF"... (English is a foreign language anyway).

                Greetings - Gajatko

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups