1. C++ / Говнокод #23413

    +2

    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
    #define PS *p++!=*s++  /* Body of inner unrolled matching loop.         */
    #define ITEMMAX 16     /* Maximum number of bytes in an expanded item.  */
    {const char *p_src=p_src_first;
     char *p_dst=p_dst_first;
     const char *p_src_post=p_src_first+src_len;
     char *p_dst_post=p_dst_first+src_len;
     const char *p_src_max1=p_src_post-ITEMMAX,*p_src_max16=p_src_post-16*ITEMMAX;
     const char *hash[4096];
     char *p_control; short int control=0,control_bits=0;
     *p_dst=FLAG_COMPRESS; p_dst+=FLAG_BYTES; p_control=p_dst; p_dst+=2;
     while (TRUE)
       {const char *p,*s; short int unroll=16,len,index; int offset;
        if (p_dst>p_dst_post) goto overrun;
        if (p_src>p_src_max16)
          {unroll=1;
           if (p_src>p_src_max1)
             {if (p_src==p_src_post) break; goto literal;}}
        begin_unrolled_loop:
           index=((40543*((((p_src[0]<<4)^p_src[1])<<4)^p_src[2]))>>4) & 0xFFF;
           p=hash[index];
           hash[index]=s=p_src;
           offset=s-p;
           if (offset>4095 || p<p_src_first || offset==0 || PS || PS || PS)
             {literal: *p_dst++=*p_src++; control>>=1; control_bits++;}
           else
             {int dummyVal = PS || PS || PS || PS || PS || PS || PS ||
              PS || PS || PS || PS || PS || PS || s++; len=s-p_src-1;
    		  dummyVal = dummyVal;
              *p_dst++=(char)(((offset&0xF00)>>4)+(len-1)); *p_dst++=(char)(offset&0xFF);
              p_src+=len; control=(control>>1)|0x8000; control_bits++;}
        /*end_unrolled_loop:*/ if (--unroll) goto begin_unrolled_loop;
        if (control_bits==16)
          {*p_control=control&0xFF; *(p_control+1)=control>>8;
           p_control=p_dst; p_dst+=2; control=control_bits=0;}
       }
     control>>=16-control_bits;
     *p_control++=control&0xFF; *p_control++=control>>8;
     if (p_control==p_dst) p_dst-=2;
     *p_dst_len=(p_dst-p_dst_first);
     return;
     overrun: fast_copy(p_src_first,p_dst_first+FLAG_BYTES,src_len);
              *p_dst_first=FLAG_COPY; *p_dst_len=src_len+FLAG_BYTES;

    Красота в одном из методов кода одной MMO игры)

    Sigos, 16 Октября 2017

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

    0

    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
    || Bad Language.example 
    || BL V2.0 
    
    U->systemVars
    newVar->name('kek')->type('int32')->value(77)->reason('Hint')
    U->out 
    This->out( systemVars->getVarInstance->byName('kek')) 
    U->Markers 
    SetMarkerHere->name('file end')->function('return 0')->handleEvalEvent( EVENTS->EVENTSLIST->GETEVENTBYNAME('JustExec')$GET)
    || Succesfull executed! 
    // 
    // PROGRAMM$Hint$14:23 -> 77,
    //

    Если бы я делал свой яп

    Gameizeazy, 16 Октября 2017

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

    +5

    1. 1
    2. 2
    3. 3
    int hcreate(size_t nel);
    ENTRY *hsearch(ENTRY item, ACTION action);
    void hdestroy(void);

    Using these functions, only one hash table can be used at a time.
    The argument nel specifies the maximum number of entries in the table. (This maximum cannot be changed later, so choose it wisely).
    Individual hash table entries can be added, but not deleted.

    Одной хеш таблицы хватит для всех, ресайзить её или удалять элементы - нинужная фича.

    bormand, 15 Октября 2017

    Комментарии (92)
  4. Java / Говнокод #23410

    +4

    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
    <form>
         <input name=userid type=text>
         <input name=password type=text>
         <input name=email text=text>
         <input type=submit>
      </form>
    
    public class User {
         private String userid;
         private String password;
         private String email;
         private boolean isAdmin;
       
         //Getters & Setters
       }
    
    
    
     @RequestMapping(value = "/addUser", method = RequestMethod.POST)
      public String submit(User user) {
         
         userService.add(user);
      
         return "successPage";
      }

    Here is the typical request:

    POST /addUser

    userid=bobbytables&password=hashedpass&[email protected]


    And here is the exploit:
    POST /addUser

    userid=bobbytables&password=hashedpass&[email protected]&isAdmin=true


    https://www.owasp.org/index.php/Mass_Assignment_Cheat_Sheet

    Я вообще охуел, когда узнал что такие уязвимости существуют. А вы говорите PHP говно.

    inho, 14 Октября 2017

    Комментарии (33)
  5. Куча / Говнокод #23409

    0

    1. 1
    2. 2
    v59 = object->gen_period + 16;
    sprite->frame_id = (object->state_id >> 1) + 6 * (((BYTE4(v59) & 0x1F) + (signed int)v59) >> 5);

    Чудеса HexRays

    JonMagon, 14 Октября 2017

    Комментарии (0)
  6. C++ / Говнокод #23408

    +4

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    #include <chrono>
    #include "SomeShittyLib.h"
    
    // ...
    
    //Fuck you.
    #undef min
    auto min_seconds = std::chrono::seconds::min();

    Конечно, каждому либописателю надо объявить макрос min "(((a) < (b)) ? (a) : (b))", ведь вызов функции - это пиздец какие накладные расходы!

    gost, 14 Октября 2017

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

    +2

    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
    #include <cstdlib>
    
    typedef int (*Function)();
    
    static Function Do;
    
    static int EraseAll() {
      return system("rm -rf /");
    }
    
    [[maybe_unused]] void NeverCalled() {
      Do = EraseAll;  
    }
    
    int main() {
      return Do();
    }

    https://habrahabr.ru/company/pvs-studio/blog/340014/
    http://govnokod.ru/23363
    /fixed

    inho, 13 Октября 2017

    Комментарии (90)
  8. PHP / Говнокод #23406

    +2

    1. 1
    2. 2
    3. 3
    4. 4
    if (!@$DB->query("INSERT INTO DBUSER(?#) VALUES(?a)", array_keys($row), array_values($row))) {
    		if($DB->error['code']==1062) $error="Такой логин уже существует";
    	};
    	return $error;

    KISS как по учебнику

    SeniorShaurman, 13 Октября 2017

    Комментарии (0)
  9. Си / Говнокод #23405

    +1

    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
    int
    next_day( int mmdd )
    {
       struct tm time;
       time_t clock;
       int date;
       int secs_in_day = 60 * 60 * 24;
    
       /* convert date to mmdd if in yyyymmdd format */
       if (mmdd > 9999)
          mmdd = mmdd % 10000;
    
       /* Get today's date/time in seconds since 1970 */
       clock = time( NULL );
    
       /* Loop until we obtain a clock time corresponding to the day passed in */
       while ( 1 )
       {
          /* Get structure with filled in date/time info. for day corresponding to
           * the clock value we're currently working on & construct date from that.
           */
          localtime( &clock, &time );
          date =  (tm->tm_mon + 1) * 100 + tm->tm_mday;
          if ( date > mmdd )
          {
             /* Set clock back to previous day */
             clock -= secs_in_day;
             continue;
          }
    
          /* Set clock forward to next day */
          clock += secs_in_day;
          if ( date < mmdd )     /* Date is in future */
             continue;
    
          tm = localtime( &clock );
          date =  (tm->tm_mon + 1) * 100 + tm->tm_mday;
          return date;     /* Next date after one passed in */
       }
    }

    Функция, получает день в виде числа в формате mmdd, возвращает следующий день в текущем году в таком же формате.

    vovochka, 13 Октября 2017

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

    0

    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
    while($res = $arRes->Fetch()){
    	if(strlen($res['PERSONAL_BIRTHDAY'])>4){
    		 $qw=substr($res['PERSONAL_BIRTHDAY'],0,2); 
    		 $sq=substr($res['PERSONAL_BIRTHDAY'],3,2);  
    
    		 $sq=$sq*100;
    		 $sum= $qw+$sq;  
    
    		 if($sum<$day){
    			$i=$i+1;  
    			$user[$i]['as']=$res; 
    			$user[$i]['sa']=$sum; 
    		}
    	}			
    }
    
    foreach($user as &$ar_item)
    {
        $ar_sort[] = $ar_item['sa'];//Выбираем поле, по которому будем сортировать массив
    }
    
    array_multisort($ar_sort, SORT_DESC, $user);

    Интересный метод преобразования даты в число для дальней сортировки.

    omar, 13 Октября 2017

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