ruby-lsapi 4.2 → 4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7071cdbea2aaa5b5e3e15d81cb659dbcdd4f0ec2
4
- data.tar.gz: c224835bd8b574e1a697cbe1754a21f01bec9a5f
3
+ metadata.gz: f50f52a087ccb168677d89ab894b8588abec069e
4
+ data.tar.gz: 3eebc21ef0cac31cf1f6142a16aab8fe48a1bfd2
5
5
  SHA512:
6
- metadata.gz: b00c35195f8785e6196f1b2ab97d3bac71ad795b7290015e5bb2f419d1a2477d44b27088d019f329d4c13ba11b672417bf78c4189a43ecb9b1465c58c60c7046
7
- data.tar.gz: a623cc9fcd25ab6ce7e6c41d50ddc8d19c5b020d23fff9ad5890483346a89ae01ab4ab466f85bef896745f74faddf7581f4a9b01c7ca8ef42122a69a36fa84cf
6
+ metadata.gz: f3143175c96d841ac986629da7208a026df9eda49be225d031fc8fd21f06c18e64ba9a3da53066c427ee4a4d0a54ca86f9b8ec18b4b0b2156c06cb2ca6db4262
7
+ data.tar.gz: 7066ddb8f448c3fda956e6b5b29475d15ccaa96e6f8b518359c973f3b66100324d2712ff8af0f89b47b844b9ec94b8382a2ae92f24d61405cbf05ee48057b0b8
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright (c) 2002-2014, Lite Speed Technologies Inc.
2
+ Copyright (c) 2002-2015, Lite Speed Technologies Inc.
3
3
  All rights reserved.
4
4
 
5
5
  Redistribution and use in source and binary forms, with or without
@@ -30,6 +30,7 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30
30
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
31
  */
32
32
 
33
+
33
34
  #ifndef _LSAPIDEF_H_
34
35
  #define _LSAPIDEF_H_
35
36
 
@@ -4,18 +4,18 @@ All rights reserved.
4
4
 
5
5
  Redistribution and use in source and binary forms, with or without
6
6
  modification, are permitted provided that the following conditions are
7
- met:
7
+ met:
8
8
 
9
9
  * Redistributions of source code must retain the above copyright
10
- notice, this list of conditions and the following disclaimer.
10
+ notice, this list of conditions and the following disclaimer.
11
11
  * Redistributions in binary form must reproduce the above
12
12
  copyright notice, this list of conditions and the following
13
13
  disclaimer in the documentation and/or other materials provided
14
- with the distribution.
14
+ with the distribution.
15
15
  * Neither the name of the Lite Speed Technologies Inc nor the
16
16
  names of its contributors may be used to endorse or promote
17
17
  products derived from this software without specific prior
18
- written permission.
18
+ written permission.
19
19
 
20
20
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
21
  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@@ -27,7 +27,7 @@ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
27
  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
28
  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
29
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
31
  */
32
32
 
33
33
 
@@ -110,7 +110,7 @@ static int s_pid_dump_debug_info = 0;
110
110
 
111
111
  LSAPI_Request g_req = { -1, -1 };
112
112
 
113
- static char s_pSecret[24];
113
+ static char s_secret[24];
114
114
 
115
115
 
116
116
  void Flush_RespBuf_r( LSAPI_Request * pReq );
@@ -135,7 +135,7 @@ static const char *CGI_HEADERS[H_TRANSFER_ENCODING+1] =
135
135
  "HTTP_VIA",
136
136
  "HTTP_TRANSFER_ENCODING"
137
137
  };
138
-
138
+
139
139
  static int CGI_HEADER_LEN[H_TRANSFER_ENCODING+1] =
140
140
  { 11, 19, 20, 20, 18, 15, 12, 14, 11, 12, 9, 11, 12, 15, 18,
141
141
  22, 13, 18, 13, 24, 15, 10, 20, 8, 22 };
@@ -166,7 +166,7 @@ static int HTTP_HEADER_LEN[H_TRANSFER_ENCODING+1] =
166
166
  { 6, 14, 15, 15, 13, 10, 12, 14, 6, 7, 4, 6, 7, 10, //user-agent
167
167
  13,17, 8, 13, 8, 19, 10, 5, 15, 3, 17
168
168
  };
169
-
169
+
170
170
  static void lsapi_sigpipe( int sig )
171
171
  {
172
172
  }
@@ -178,7 +178,7 @@ static void lsapi_siguser1( int sig )
178
178
  #ifndef sighandler_t
179
179
  typedef void (*sighandler_t)(int);
180
180
  #endif
181
-
181
+
182
182
  static void lsapi_signal(int signo, sighandler_t handler)
183
183
  {
184
184
  struct sigaction sa;
@@ -196,12 +196,12 @@ static void lsapi_signal(int signo, sighandler_t handler)
196
196
 
197
197
 
198
198
  static int s_enable_core_dump = 0;
199
- static void lsapi_enable_core_dump()
199
+ static void lsapi_enable_core_dump(void)
200
200
  {
201
201
  #if defined(__FreeBSD__ ) || defined(__NetBSD__) || defined(__OpenBSD__) \
202
202
  || defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)
203
203
  int mib[2];
204
- size_t len;
204
+ size_t len;
205
205
 
206
206
  len = 2;
207
207
  if ( sysctlnametomib("kern.sugid_coredump", mib, &len) == 0 )
@@ -212,7 +212,7 @@ static void lsapi_enable_core_dump()
212
212
  "core dump may not be available!");
213
213
  }
214
214
 
215
-
215
+
216
216
  #endif
217
217
 
218
218
  #if defined(linux) || defined(__linux) || defined(__linux__) || defined(__gnu_linux__)
@@ -419,7 +419,7 @@ static int allocateEnvList( struct LSAPI_key_value_pair ** pEnvList,
419
419
  int *curSize, int newSize )
420
420
  {
421
421
  struct LSAPI_key_value_pair * pBuf;
422
- if ( *curSize >= newSize )
422
+ if ( *curSize >= newSize )
423
423
  return 0;
424
424
  if ( newSize > 8192 )
425
425
  return -1;
@@ -493,7 +493,7 @@ static inline void swapIntEndian( int * pInteger )
493
493
  b = p[1];
494
494
  p[1] = p[2];
495
495
  p[2] = b;
496
-
496
+
497
497
  }
498
498
 
499
499
  static inline void fixEndian( LSAPI_Request * pReq )
@@ -541,6 +541,40 @@ static void fixHeaderIndexEndian( LSAPI_Request * pReq )
541
541
  }
542
542
  }
543
543
 
544
+
545
+ static int validateHeaders( LSAPI_Request * pReq )
546
+ {
547
+ int totalLen = pReq->m_pHeader->m_httpHeaderLen;
548
+ int i;
549
+ for(i = 0; i < H_TRANSFER_ENCODING; ++i)
550
+ {
551
+ if ( pReq->m_pHeaderIndex->m_headerOff[i] )
552
+ {
553
+ if (pReq->m_pHeaderIndex->m_headerOff[i] > totalLen
554
+ || pReq->m_pHeaderIndex->m_headerLen[i]
555
+ + pReq->m_pHeaderIndex->m_headerOff[i] > totalLen)
556
+ return -1;
557
+ }
558
+ }
559
+ if (pReq->m_pHeader->m_cntUnknownHeaders > 0)
560
+ {
561
+ struct lsapi_header_offset * pCur, *pEnd;
562
+ pCur = pReq->m_pUnknownHeader;
563
+ pEnd = pCur + pReq->m_pHeader->m_cntUnknownHeaders;
564
+ while( pCur < pEnd )
565
+ {
566
+ if (pCur->nameOff > totalLen
567
+ || pCur->nameOff + pCur->nameLen > totalLen
568
+ || pCur->valueOff > totalLen
569
+ || pCur->valueOff + pCur->valueLen > totalLen)
570
+ return -1;
571
+ ++pCur;
572
+ }
573
+ }
574
+ return 0;
575
+ }
576
+
577
+
544
578
  static uid_t s_uid = 0;
545
579
  static uid_t s_defaultUid; //web server need set this
546
580
  static gid_t s_defaultGid;
@@ -562,13 +596,13 @@ static int (*fp_lve_destroy)(struct liblve *) = NULL;
562
596
  static int (*fp_lve_enter)(struct liblve *, uint32_t, int32_t, int32_t, uint32_t *) = NULL;
563
597
  static int (*fp_lve_leave)(struct liblve *, uint32_t *) = NULL;
564
598
  static int (*fp_lve_jail)( struct passwd *, char *) = NULL;
565
- static int lsapi_load_lve_lib()
599
+ static int lsapi_load_lve_lib(void)
566
600
  {
567
601
  s_liblve = dlopen("liblve.so.0", RTLD_LAZY);
568
602
  if (s_liblve)
569
603
  {
570
604
  fp_lve_is_available = dlsym(s_liblve, "lve_is_available");
571
- if (dlerror() == NULL)
605
+ if (dlerror() == NULL)
572
606
  {
573
607
  if ( !(*fp_lve_is_available)() )
574
608
  {
@@ -590,11 +624,11 @@ static int lsapi_load_lve_lib()
590
624
  return (s_liblve)? 0 : -1;
591
625
  }
592
626
 
593
- static int init_lve_ex()
627
+ static int init_lve_ex(void)
594
628
  {
595
629
  int rc;
596
630
  if ( !s_liblve )
597
- return -1;
631
+ return -1;
598
632
  fp_lve_instance_init = dlsym(s_liblve, "lve_instance_init");
599
633
  fp_lve_destroy = dlsym(s_liblve, "lve_destroy");
600
634
  fp_lve_enter = dlsym(s_liblve, "lve_enter");
@@ -602,13 +636,13 @@ static int init_lve_ex()
602
636
  if ( s_enable_lve >= LSAPI_CAGEFS_ENABLED )
603
637
  fp_lve_jail = dlsym(s_liblve, "jail" );
604
638
 
605
- if ( s_lve == NULL )
639
+ if ( s_lve == NULL )
606
640
  {
607
641
  rc = (*fp_lve_instance_init)(NULL);
608
642
  s_lve = malloc(rc);
609
643
  }
610
644
  rc = (*fp_lve_instance_init)(s_lve);
611
- if (rc != 0)
645
+ if (rc != 0)
612
646
  {
613
647
  perror( "LSAPI: Unable to initialize LVE" );
614
648
  free( s_lve );
@@ -616,7 +650,7 @@ static int init_lve_ex()
616
650
  return -1;
617
651
  }
618
652
  return 0;
619
-
653
+
620
654
  }
621
655
 
622
656
  #endif
@@ -652,7 +686,7 @@ static int readSecret( const char * pSecretFile )
652
686
  close( fd );
653
687
  return -1;
654
688
  }
655
- if ( read( fd, s_pSecret, 16 ) < 16 )
689
+ if ( read( fd, s_secret, 16 ) < 16 )
656
690
  {
657
691
  fprintf( stderr, "LSAPI: failed to read secret from secret file: %s\n", pSecretFile );
658
692
  close( fd );
@@ -662,9 +696,9 @@ static int readSecret( const char * pSecretFile )
662
696
  return 0;
663
697
  }
664
698
 
665
- int LSAPI_is_suEXEC_Daemon()
699
+ int LSAPI_is_suEXEC_Daemon(void)
666
700
  {
667
- if (( !s_uid )&&( s_pSecret[0] ))
701
+ if (( !s_uid )&&( s_secret[0] ))
668
702
  return 1;
669
703
  else
670
704
  return 0;
@@ -683,7 +717,7 @@ static int LSAPI_perror_r( LSAPI_Request * pReq, const char * pErr1, const char
683
717
 
684
718
  static int lsapi_lve_error( LSAPI_Request * pReq )
685
719
  {
686
- static const char * headers[] =
720
+ static const char * headers[] =
687
721
  {
688
722
  "Cache-Control: private, no-cache, no-store, must-revalidate, max-age=0",
689
723
  "Pragma: no-cache",
@@ -699,7 +733,7 @@ static int lsapi_lve_error( LSAPI_Request * pReq )
699
733
  "Please try again later.\n"
700
734
  "<HR>\n"
701
735
  "</BODY></HTML>\n";
702
-
736
+
703
737
  LSAPI_ErrResponse_r( pReq, 508, headers, achBody, sizeof( achBody ) - 1 );
704
738
  return 0;
705
739
  }
@@ -733,7 +767,7 @@ static int lsapi_jailLVE( LSAPI_Request * pReq, uid_t uid, struct passwd * pw )
733
767
  ret = (*fp_lve_jail)( pw, error_msg );
734
768
  if ( ret < 0 )
735
769
  {
736
- fprintf( stderr, "LSAPI (%d): LVE jail(%d) ressult: %d, error: %s !\n",
770
+ fprintf( stderr, "LSAPI (%d): LVE jail(%d) ressult: %d, error: %s !\n",
737
771
  getpid(), uid, ret, error_msg );
738
772
  LSAPI_perror_r( pReq, "LSAPI: jail() failure.", NULL );
739
773
  return -1;
@@ -744,7 +778,7 @@ static int lsapi_jailLVE( LSAPI_Request * pReq, uid_t uid, struct passwd * pw )
744
778
 
745
779
 
746
780
  #if defined(linux) || defined(__linux) || defined(__linux__) || defined(__gnu_linux__)
747
- static int lsapi_initLVE()
781
+ static int lsapi_initLVE(void)
748
782
  {
749
783
  const char * pEnv;
750
784
  if ( (pEnv = getenv( "LSAPI_LVE_ENABLE" ))!= NULL )
@@ -778,7 +812,7 @@ static int setUID_LVE(LSAPI_Request * pReq, uid_t uid, gid_t gid, const char * p
778
812
  pw = getpwuid( uid );
779
813
  #if defined(linux) || defined(__linux) || defined(__linux__) || defined(__gnu_linux__)
780
814
  if ( s_lve )
781
- {
815
+ {
782
816
  if( lsapi_enterLVE( pReq, uid ) == -1 )
783
817
  return -1;
784
818
  if ( pw && fp_lve_jail)
@@ -795,7 +829,7 @@ static int setUID_LVE(LSAPI_Request * pReq, uid_t uid, gid_t gid, const char * p
795
829
  }
796
830
  }
797
831
  #endif
798
- //if ( !uid || !gid ) //do not allow root
832
+ //if ( !uid || !gid ) //do not allow root
799
833
  //{
800
834
  // return -1;
801
835
  //}
@@ -851,7 +885,7 @@ static int setUID_LVE(LSAPI_Request * pReq, uid_t uid, gid_t gid, const char * p
851
885
  return 0;
852
886
  }
853
887
 
854
- static int lsapi_suexec_auth( LSAPI_Request *pReq,
888
+ static int lsapi_suexec_auth( LSAPI_Request *pReq,
855
889
  char * pAuth, int len, char * pUgid, int ugidLen )
856
890
  {
857
891
  lsapi_MD5_CTX md5ctx;
@@ -859,7 +893,7 @@ static int lsapi_suexec_auth( LSAPI_Request *pReq,
859
893
  if ( len < 32 )
860
894
  return -1;
861
895
  memmove( achMD5, pAuth + 16, 16 );
862
- memmove( pAuth + 16, s_pSecret, 16 );
896
+ memmove( pAuth + 16, s_secret, 16 );
863
897
  lsapi_MD5Init( &md5ctx );
864
898
  lsapi_MD5Update( &md5ctx, (unsigned char *)pAuth, 32 );
865
899
  lsapi_MD5Update( &md5ctx, (unsigned char *)pUgid, 8 );
@@ -883,7 +917,7 @@ static int lsapi_changeUGid( LSAPI_Request * pReq )
883
917
  //with special ID 0x00
884
918
  //authenticate the suEXEC request;
885
919
  //first one should be MD5( nonce + lscgid secret )
886
- //remember to clear the secret after verification
920
+ //remember to clear the secret after verification
887
921
  //it should be set at the end of special env
888
922
  i = pReq->m_pHeader->m_cntSpecialEnv - 1;
889
923
  if ( i >= 0 )
@@ -899,7 +933,7 @@ static int lsapi_changeUGid( LSAPI_Request * pReq )
899
933
  {
900
934
  --pReq->m_pHeader->m_cntSpecialEnv;
901
935
  uid = *(uint32_t *)pEnv->pValue;
902
- gid = *(((uint32_t *)pEnv->pValue) + 1 );
936
+ gid = *(((uint32_t *)pEnv->pValue) + 1 );
903
937
  //fprintf( stderr, "LSAPI: SUEXEC_UGID set UID: %d, GID: %d\n", uid, gid );
904
938
  }
905
939
  else
@@ -909,8 +943,8 @@ static int lsapi_changeUGid( LSAPI_Request * pReq )
909
943
  }
910
944
  if ( pEnv&& lsapi_suexec_auth( pReq, pAuth->pValue, pAuth->valLen, pEnv->pValue, pEnv->valLen ) == 0 )
911
945
  {
912
- //read UID, GID from specialEnv
913
-
946
+ //read UID, GID from specialEnv
947
+
914
948
  }
915
949
  else
916
950
  {
@@ -938,10 +972,10 @@ static int lsapi_changeUGid( LSAPI_Request * pReq )
938
972
  return -1;
939
973
  }
940
974
 
941
- s_uid = uid;
975
+ s_uid = uid;
942
976
 
943
977
  return 0;
944
-
978
+
945
979
  }
946
980
 
947
981
  static int parseContentLenFromHeader(LSAPI_Request * pReq)
@@ -981,12 +1015,23 @@ static int parseRequest( LSAPI_Request * pReq, int totalLen )
981
1015
  if ( parseEnv( pReq->m_pEnvList, pReq->m_pHeader->m_cntEnv,
982
1016
  &pBegin, pEnd ) == -1 )
983
1017
  return -1;
984
-
1018
+ if (pReq->m_pHeader->m_scriptFileOff < 0
1019
+ || pReq->m_pHeader->m_scriptFileOff >= totalLen
1020
+ || pReq->m_pHeader->m_scriptNameOff < 0
1021
+ || pReq->m_pHeader->m_scriptNameOff >= totalLen
1022
+ || pReq->m_pHeader->m_queryStringOff < 0
1023
+ || pReq->m_pHeader->m_queryStringOff >= totalLen
1024
+ || pReq->m_pHeader->m_requestMethodOff < 0
1025
+ || pReq->m_pHeader->m_requestMethodOff >= totalLen)
1026
+ {
1027
+ fprintf(stderr, "%d: bad request header - ERROR#1\n", getpid());
1028
+ return -1;
1029
+ }
985
1030
  pReq->m_pScriptFile = pReq->m_pReqBuf + pReq->m_pHeader->m_scriptFileOff;
986
1031
  pReq->m_pScriptName = pReq->m_pReqBuf + pReq->m_pHeader->m_scriptNameOff;
987
1032
  pReq->m_pQueryString = pReq->m_pReqBuf + pReq->m_pHeader->m_queryStringOff;
988
1033
  pReq->m_pRequestMethod = pReq->m_pReqBuf + pReq->m_pHeader->m_requestMethodOff;
989
-
1034
+
990
1035
  pBegin = pReq->m_pReqBuf + (( pBegin - pReq->m_pReqBuf + 7 ) & (~0x7));
991
1036
  pReq->m_pHeaderIndex = ( struct lsapi_http_header_index * )pBegin;
992
1037
  pBegin += sizeof( struct lsapi_http_header_index );
@@ -1007,12 +1052,19 @@ static int parseRequest( LSAPI_Request * pReq, int totalLen )
1007
1052
  {
1008
1053
  fixHeaderIndexEndian( pReq );
1009
1054
  }
1055
+
1056
+ if (validateHeaders(pReq) == -1)
1057
+ {
1058
+ fprintf(stderr, "%d: bad request header - ERROR#2\n", getpid());
1059
+ return -1;
1060
+ }
1061
+
1010
1062
  pReq->m_reqBodyLen = pReq->m_pHeader->m_reqBodyLen;
1011
1063
  if ( pReq->m_reqBodyLen == -2 )
1012
1064
  {
1013
1065
  parseContentLenFromHeader(pReq);
1014
1066
  }
1015
-
1067
+
1016
1068
  return 0;
1017
1069
  }
1018
1070
 
@@ -1044,7 +1096,7 @@ static void lsapi_sigalarm( int sig )
1044
1096
  }
1045
1097
  }
1046
1098
 
1047
- static inline int lsapi_schedule_notify()
1099
+ static inline int lsapi_schedule_notify(void)
1048
1100
  {
1049
1101
  if ( !s_notify_scheduled )
1050
1102
  {
@@ -1070,7 +1122,7 @@ static inline int lsapi_notify_pid( int fd )
1070
1122
  8 + LSAPI_PACKET_HEADER_LEN );
1071
1123
  memmove( &achBuf[8], "\0PID", 4 );
1072
1124
  *((int *)&achBuf[12]) = getpid();
1073
-
1125
+
1074
1126
  if ( write( fd, achBuf, 16 ) < 16 )
1075
1127
  return -1;
1076
1128
  return 0;
@@ -1094,7 +1146,7 @@ static inline int init_conn_key( int fd )
1094
1146
  < LSAPI_PACKET_HEADER_LEN+8 )
1095
1147
  return -1;
1096
1148
  return 0;
1097
-
1149
+
1098
1150
 
1099
1151
  }
1100
1152
 
@@ -1152,8 +1204,11 @@ static int readReq( LSAPI_Request * pReq )
1152
1204
  pReq->m_reqState = LSAPI_ST_REQ_BODY | LSAPI_ST_RESP_HEADER;
1153
1205
 
1154
1206
  if ( !s_uid )
1207
+ {
1155
1208
  if ( lsapi_changeUGid( pReq ) )
1156
1209
  return -1;
1210
+ memset(s_secret, 0, sizeof(s_secret));
1211
+ }
1157
1212
  pReq->m_bufProcessed = packetLen;
1158
1213
 
1159
1214
  //OPTIMIZATION
@@ -1173,16 +1228,16 @@ int LSAPI_Init(void)
1173
1228
  if ( !g_inited )
1174
1229
  {
1175
1230
  s_uid = geteuid();
1176
- s_pSecret[0] = 0;
1231
+ s_secret[0] = 0;
1177
1232
  lsapi_signal(SIGPIPE, lsapi_sigpipe);
1178
1233
  lsapi_signal(SIGUSR1, lsapi_siguser1);
1179
1234
 
1180
1235
  #if defined(SIGXFSZ) && defined(SIG_IGN)
1181
1236
  signal(SIGXFSZ, SIG_IGN);
1182
1237
  #endif
1183
- /* let STDOUT function as STDERR,
1238
+ /* let STDOUT function as STDERR,
1184
1239
  just in case writing to STDOUT directly */
1185
- dup2( 2, 1 );
1240
+ dup2( 2, 1 );
1186
1241
  if ( LSAPI_InitRequest( &g_req, LSAPI_SOCK_FILENO ) == -1 )
1187
1242
  return -1;
1188
1243
  g_inited = 1;
@@ -1222,8 +1277,8 @@ int LSAPI_InitRequest( LSAPI_Request * pReq, int fd )
1222
1277
  {
1223
1278
  fd = dup( fd );
1224
1279
  newfd = open( "/dev/null", O_RDWR );
1225
- dup2( newfd, STDIN_FILENO );
1226
- }
1280
+ dup2( newfd, STDIN_FILENO );
1281
+ }
1227
1282
 
1228
1283
  if ( isPipe( fd ) )
1229
1284
  {
@@ -1256,7 +1311,7 @@ int LSAPI_Accept_r( LSAPI_Request * pReq )
1256
1311
  char achPeer[128];
1257
1312
  socklen_t len;
1258
1313
  int nodelay = 1;
1259
-
1314
+
1260
1315
  if ( !pReq )
1261
1316
  return -1;
1262
1317
  if ( LSAPI_Finish_r( pReq ) == -1 )
@@ -1282,7 +1337,7 @@ int LSAPI_Accept_r( LSAPI_Request * pReq )
1282
1337
  {
1283
1338
  lsapi_set_nblock( pReq->m_fd , 0 );
1284
1339
  if (((struct sockaddr *)&achPeer)->sa_family == AF_INET )
1285
- {
1340
+ {
1286
1341
  setsockopt(pReq->m_fd, IPPROTO_TCP, TCP_NODELAY,
1287
1342
  (char *)&nodelay, sizeof(nodelay));
1288
1343
  }
@@ -1326,7 +1381,7 @@ int LSAPI_Finish_r( LSAPI_Request * pReq )
1326
1381
  {
1327
1382
  Flush_RespBuf_r( pReq );
1328
1383
  }
1329
-
1384
+
1330
1385
  pReq->m_pIovecCur->iov_base = (void *)&finish;
1331
1386
  pReq->m_pIovecCur->iov_len = LSAPI_PACKET_HEADER_LEN;
1332
1387
  pReq->m_totalLen += LSAPI_PACKET_HEADER_LEN;
@@ -1344,7 +1399,7 @@ void LSAPI_Reset_r( LSAPI_Request * pReq )
1344
1399
  pReq->m_pRespBufPos = pReq->m_pRespBuf;
1345
1400
  pReq->m_pIovecCur = pReq->m_pIovecToWrite = pReq->m_pIovec + 1;
1346
1401
  pReq->m_pRespHeaderBufPos = pReq->m_pRespHeaderBuf;
1347
-
1402
+
1348
1403
  memset( &pReq->m_pHeaderIndex, 0,
1349
1404
  (char *)(pReq->m_respHeaderLen) - (char *)&pReq->m_pHeaderIndex );
1350
1405
  }
@@ -1359,7 +1414,7 @@ int LSAPI_Release_r( LSAPI_Request * pReq )
1359
1414
  if ( pReq->m_pEnvList )
1360
1415
  free( pReq->m_pEnvList );
1361
1416
  if ( pReq->m_pRespHeaderBuf )
1362
- free( pReq->m_pRespHeaderBuf );
1417
+ free( pReq->m_pRespHeaderBuf );
1363
1418
  return 0;
1364
1419
  }
1365
1420
 
@@ -1395,7 +1450,7 @@ static int readBodyToReqBuf( LSAPI_Request * pReq )
1395
1450
  return -1;
1396
1451
  if ( len > bodyLeft )
1397
1452
  len = bodyLeft;
1398
-
1453
+
1399
1454
  len = lsapi_read( pReq->m_fd, pReq->m_pReqBuf + pReq->m_bufRead, len );
1400
1455
  if ( len > 0 )
1401
1456
  pReq->m_bufRead += len;
@@ -1431,7 +1486,7 @@ int LSAPI_ReqBodyGetLine_r( LSAPI_Request * pReq, char * pBuf, size_t bufLen, in
1431
1486
  *getLF = 0;
1432
1487
  while( (left = pBufEnd - pBufCur ) > 0 )
1433
1488
  {
1434
-
1489
+
1435
1490
  len = pReq->m_bufRead - pReq->m_bufProcessed;
1436
1491
  if ( len <= 0 )
1437
1492
  {
@@ -1452,7 +1507,7 @@ int LSAPI_ReqBodyGetLine_r( LSAPI_Request * pReq, char * pBuf, size_t bufLen, in
1452
1507
  pReq->m_bufProcessed += len;
1453
1508
 
1454
1509
  pReq->m_reqBodyRead += len;
1455
-
1510
+
1456
1511
  if ( p )
1457
1512
  {
1458
1513
  *getLF = 1;
@@ -1460,7 +1515,7 @@ int LSAPI_ReqBodyGetLine_r( LSAPI_Request * pReq, char * pBuf, size_t bufLen, in
1460
1515
  }
1461
1516
  }
1462
1517
  *pBufCur = 0;
1463
-
1518
+
1464
1519
  return pBufCur - pBuf;
1465
1520
  }
1466
1521
 
@@ -1470,21 +1525,21 @@ ssize_t LSAPI_ReadReqBody_r( LSAPI_Request * pReq, char * pBuf, size_t bufLen )
1470
1525
  ssize_t len;
1471
1526
  off_t total;
1472
1527
  /* char *pOldBuf = pBuf; */
1473
- if (!pReq || (pReq->m_fd ==-1) || ( !pBuf )||(bufLen < 0 ))
1528
+ if (!pReq || (pReq->m_fd ==-1) || ( !pBuf )||((ssize_t)bufLen < 0 ))
1474
1529
  return -1;
1475
1530
 
1476
1531
  total = pReq->m_reqBodyLen - pReq->m_reqBodyRead;
1477
-
1532
+
1478
1533
  if ( total <= 0 )
1479
1534
  return 0;
1480
- if ( total < bufLen )
1535
+ if ( total < (ssize_t)bufLen )
1481
1536
  bufLen = total;
1482
1537
 
1483
1538
  total = 0;
1484
1539
  len = pReq->m_bufRead - pReq->m_bufProcessed;
1485
1540
  if ( len > 0 )
1486
1541
  {
1487
- if ( len > bufLen )
1542
+ if ( len > (ssize_t)bufLen )
1488
1543
  len = bufLen;
1489
1544
  memmove( pBuf, pReq->m_pReqBuf + pReq->m_bufProcessed, len );
1490
1545
  pReq->m_bufProcessed += len;
@@ -1510,7 +1565,7 @@ ssize_t LSAPI_ReadReqBody_r( LSAPI_Request * pReq, char * pBuf, size_t bufLen )
1510
1565
  }
1511
1566
  pReq->m_reqBodyRead += total;
1512
1567
  return total;
1513
-
1568
+
1514
1569
  }
1515
1570
 
1516
1571
 
@@ -1523,7 +1578,7 @@ ssize_t LSAPI_Write_r( LSAPI_Request * pReq, const char * pBuf, size_t len )
1523
1578
  ssize_t toWrite;
1524
1579
  ssize_t packetLen;
1525
1580
  int skip = 0;
1526
-
1581
+
1527
1582
  if ( !pReq || !pBuf || (pReq->m_fd == -1) )
1528
1583
  return -1;
1529
1584
  if ( pReq->m_reqState & LSAPI_ST_RESP_HEADER )
@@ -1542,19 +1597,19 @@ ssize_t LSAPI_Write_r( LSAPI_Request * pReq, const char * pBuf, size_t len )
1542
1597
  }
1543
1598
  pReq->m_reqState |= LSAPI_ST_RESP_BODY;
1544
1599
 
1545
- if ( (len - skip) < pReq->m_pRespBufEnd - pReq->m_pRespBufPos )
1600
+ if ( ((ssize_t)len - skip) < pReq->m_pRespBufEnd - pReq->m_pRespBufPos )
1546
1601
  {
1547
1602
  memmove( pReq->m_pRespBufPos, pBuf + skip, len - skip );
1548
1603
  pReq->m_pRespBufPos += len - skip;
1549
1604
  return len;
1550
1605
  }
1551
-
1552
-
1606
+
1607
+
1553
1608
  pHeader = pReq->m_respPktHeader;
1554
1609
  p = pBuf + skip;
1555
1610
  pEnd = pBuf + len;
1556
1611
  bufLen = pReq->m_pRespBufPos - pReq->m_pRespBuf;
1557
-
1612
+
1558
1613
  while( ( toWrite = pEnd - p ) > 0 )
1559
1614
  {
1560
1615
  packetLen = toWrite + bufLen;
@@ -1563,7 +1618,7 @@ ssize_t LSAPI_Write_r( LSAPI_Request * pReq, const char * pBuf, size_t len )
1563
1618
  packetLen = LSAPI_MAX_DATA_PACKET_LEN;
1564
1619
  toWrite = packetLen - bufLen;
1565
1620
  }
1566
-
1621
+
1567
1622
  lsapi_buildPacketHeader( pHeader, LSAPI_RESP_STREAM,
1568
1623
  packetLen + LSAPI_PACKET_HEADER_LEN );
1569
1624
  pReq->m_totalLen += packetLen + LSAPI_PACKET_HEADER_LEN;
@@ -1577,7 +1632,7 @@ ssize_t LSAPI_Write_r( LSAPI_Request * pReq, const char * pBuf, size_t len )
1577
1632
  pReq->m_pIovecCur->iov_base = (void *)pReq->m_pRespBuf;
1578
1633
  pReq->m_pIovecCur->iov_len = bufLen;
1579
1634
  pReq->m_pRespBufPos = pReq->m_pRespBuf;
1580
- ++pReq->m_pIovecCur;
1635
+ ++pReq->m_pIovecCur;
1581
1636
  bufLen = 0;
1582
1637
  }
1583
1638
 
@@ -1599,7 +1654,7 @@ ssize_t LSAPI_Write_r( LSAPI_Request * pReq, const char * pBuf, size_t len )
1599
1654
  return p - pBuf;
1600
1655
  }
1601
1656
 
1602
- #if defined(__FreeBSD__ ) || defined(__NetBSD__) || defined(__OpenBSD__)
1657
+ #if defined(__FreeBSD__ ) || defined(__NetBSD__) || defined(__OpenBSD__)
1603
1658
  ssize_t gsendfile( int fdOut, int fdIn, off_t* off, size_t size )
1604
1659
  {
1605
1660
  ssize_t ret;
@@ -1628,7 +1683,7 @@ ssize_t gsendfile( int fdOut, int fdIn, off_t* off, size_t size )
1628
1683
  return ret;
1629
1684
  }
1630
1685
  #endif
1631
-
1686
+
1632
1687
  #if defined(sun) || defined(__sun)
1633
1688
  #include <sys/sendfile.h>
1634
1689
  ssize_t gsendfile( int fdOut, int fdIn, off_t *off, size_t size )
@@ -1674,16 +1729,16 @@ ssize_t LSAPI_sendfile_r( LSAPI_Request * pReq, int fdIn, off_t* off, size_t siz
1674
1729
  LSAPI_FinalizeRespHeaders_r( pReq );
1675
1730
  }
1676
1731
  pReq->m_reqState |= LSAPI_ST_RESP_BODY;
1677
-
1732
+
1678
1733
  LSAPI_Flush_r(pReq);
1679
-
1734
+
1680
1735
  lsapi_buildPacketHeader( pHeader, LSAPI_RESP_STREAM,
1681
1736
  size + LSAPI_PACKET_HEADER_LEN );
1682
-
1737
+
1683
1738
 
1684
1739
  if (write(pReq->m_fd, (const char *) pHeader, LSAPI_PACKET_HEADER_LEN ) != LSAPI_PACKET_HEADER_LEN)
1685
1740
  return -1;
1686
-
1741
+
1687
1742
  return gsendfile( pReq->m_fd, fdIn, off, size );
1688
1743
  }
1689
1744
 
@@ -1706,7 +1761,7 @@ void Flush_RespBuf_r( LSAPI_Request * pReq )
1706
1761
  pReq->m_pIovecCur->iov_base = (void *)pReq->m_pRespBuf;
1707
1762
  pReq->m_pIovecCur->iov_len = bufLen;
1708
1763
  pReq->m_pRespBufPos = pReq->m_pRespBuf;
1709
- ++pReq->m_pIovecCur;
1764
+ ++pReq->m_pIovecCur;
1710
1765
  bufLen = 0;
1711
1766
  }
1712
1767
  }
@@ -1738,11 +1793,11 @@ int LSAPI_Flush_r( LSAPI_Request * pReq )
1738
1793
  {
1739
1794
  Flush_RespBuf_r( pReq );
1740
1795
  }
1741
-
1796
+
1742
1797
  n = pReq->m_pIovecCur - pReq->m_pIovecToWrite;
1743
1798
  if ( n > 0 )
1744
1799
  {
1745
-
1800
+
1746
1801
  ret = lsapi_writev( pReq->m_fd, &pReq->m_pIovecToWrite,
1747
1802
  n, pReq->m_totalLen );
1748
1803
  if ( ret < pReq->m_totalLen )
@@ -1768,7 +1823,7 @@ ssize_t LSAPI_Write_Stderr_r( LSAPI_Request * pReq, const char * pBuf, size_t le
1768
1823
  int ret;
1769
1824
  struct iovec iov[2];
1770
1825
  struct iovec *pIov;
1771
-
1826
+
1772
1827
  if ( !pReq )
1773
1828
  return -1;
1774
1829
  if (( pReq->m_fd == -1 )||(pReq->m_fd == pReq->m_fdListen ))
@@ -1777,7 +1832,7 @@ ssize_t LSAPI_Write_Stderr_r( LSAPI_Request * pReq, const char * pBuf, size_t le
1777
1832
  {
1778
1833
  LSAPI_Flush_r( pReq );
1779
1834
  }
1780
-
1835
+
1781
1836
  p = pBuf;
1782
1837
  pEnd = pBuf + len;
1783
1838
 
@@ -1901,7 +1956,7 @@ struct _headerInfo
1901
1956
  int compareValueLocation(const void * v1, const void *v2 )
1902
1957
  {
1903
1958
  return ((const struct _headerInfo *)v1)->_value -
1904
- ((const struct _headerInfo *)v2)->_value;
1959
+ ((const struct _headerInfo *)v2)->_value;
1905
1960
  }
1906
1961
 
1907
1962
  int LSAPI_ForeachOrgHeader_r( LSAPI_Request * pReq,
@@ -1932,7 +1987,7 @@ int LSAPI_ForeachOrgHeader_r( LSAPI_Request * pReq,
1932
1987
  headers[count]._value = pValue;
1933
1988
  headers[count]._valueLen = len;
1934
1989
  ++count;
1935
-
1990
+
1936
1991
  //ret = (*fn)( HTTP_HEADERS[i], HTTP_HEADER_LEN[i],
1937
1992
  // pValue, len, arg );
1938
1993
  //if ( ret <= 0 )
@@ -1961,7 +2016,7 @@ int LSAPI_ForeachOrgHeader_r( LSAPI_Request * pReq,
1961
2016
  ++count;
1962
2017
  if ( count == 512 )
1963
2018
  break;
1964
- //ret = (*fn)( pKey, keyLen,
2019
+ //ret = (*fn)( pKey, keyLen,
1965
2020
  // pValue, pCur->valueLen, arg );
1966
2021
  //if ( ret <= 0 )
1967
2022
  // return ret;
@@ -1971,13 +2026,13 @@ int LSAPI_ForeachOrgHeader_r( LSAPI_Request * pReq,
1971
2026
  qsort( headers, count, sizeof( struct _headerInfo ), compareValueLocation );
1972
2027
  for( i = 0; i < count; ++i )
1973
2028
  {
1974
- ret = (*fn)( headers[i]._name, headers[i]._nameLen,
2029
+ ret = (*fn)( headers[i]._name, headers[i]._nameLen,
1975
2030
  headers[i]._value, headers[i]._valueLen, arg );
1976
2031
  if ( ret <= 0 )
1977
2032
  return ret;
1978
2033
  }
1979
2034
  return count;
1980
-
2035
+
1981
2036
  }
1982
2037
 
1983
2038
 
@@ -2038,7 +2093,7 @@ int LSAPI_ForeachHeader_r( LSAPI_Request * pReq,
2038
2093
 
2039
2094
  pValue = pReq->m_pHttpHeader + pCur->valueOff;
2040
2095
  *(pValue + pCur->valueLen ) = 0;
2041
- ret = (*fn)( achHeaderName, keyLen,
2096
+ ret = (*fn)( achHeaderName, keyLen,
2042
2097
  pValue, pCur->valueLen, arg );
2043
2098
  if ( ret <= 0 )
2044
2099
  return ret;
@@ -2046,7 +2101,7 @@ int LSAPI_ForeachHeader_r( LSAPI_Request * pReq,
2046
2101
  }
2047
2102
  }
2048
2103
  return count + pReq->m_pHeader->m_cntUnknownHeaders;
2049
-
2104
+
2050
2105
  }
2051
2106
 
2052
2107
  static int EnvForeach( struct LSAPI_key_value_pair * pEnv,
@@ -2115,7 +2170,7 @@ int LSAPI_FinalizeRespHeaders_r( LSAPI_Request * pReq )
2115
2170
  pReq->m_totalLen += pReq->m_pIovecCur->iov_len;
2116
2171
  ++pReq->m_pIovecCur;
2117
2172
  }
2118
-
2173
+
2119
2174
  pReq->m_pIovec->iov_len = sizeof( struct lsapi_resp_header)
2120
2175
  + pReq->m_respHeader.m_respInfo.m_cntHeaders * sizeof( short );
2121
2176
  pReq->m_totalLen += pReq->m_pIovec->iov_len;
@@ -2128,11 +2183,11 @@ int LSAPI_FinalizeRespHeaders_r( LSAPI_Request * pReq )
2128
2183
  }
2129
2184
 
2130
2185
 
2131
- int LSAPI_AppendRespHeader2_r( LSAPI_Request * pReq, const char * pHeaderName,
2186
+ int LSAPI_AppendRespHeader2_r( LSAPI_Request * pReq, const char * pHeaderName,
2132
2187
  const char * pHeaderValue )
2133
2188
  {
2134
2189
  int nameLen, valLen, len;
2135
- if ( !pReq || !pHeaderName || !pHeaderValue )
2190
+ if ( !pReq || !pHeaderName || !pHeaderValue )
2136
2191
  return -1;
2137
2192
  if ( pReq->m_reqState & LSAPI_ST_RESP_BODY )
2138
2193
  return -1;
@@ -2276,7 +2331,7 @@ int LSAPI_ParseSockAddr( const char * pBind, struct sockaddr * pAddr )
2276
2331
  struct addrinfo *res, hints;
2277
2332
  int doAddrInfo = 0;
2278
2333
  int port;
2279
-
2334
+
2280
2335
  if ( !pBind )
2281
2336
  return -1;
2282
2337
 
@@ -2300,7 +2355,7 @@ int LSAPI_ParseSockAddr( const char * pBind, struct sockaddr * pAddr )
2300
2355
  if ( !pEnd )
2301
2356
  return -1;
2302
2357
  *pEnd++ = 0;
2303
-
2358
+
2304
2359
  if ( *p == '*' )
2305
2360
  {
2306
2361
  strcpy( achAddr, "::" );
@@ -2315,7 +2370,7 @@ int LSAPI_ParseSockAddr( const char * pBind, struct sockaddr * pAddr )
2315
2370
  if ( !pEnd )
2316
2371
  return -1;
2317
2372
  *pEnd++ = 0;
2318
-
2373
+
2319
2374
  doAddrInfo = 0;
2320
2375
  if ( *p == '*' )
2321
2376
  {
@@ -2335,7 +2390,7 @@ int LSAPI_ParseSockAddr( const char * pBind, struct sockaddr * pAddr )
2335
2390
  }
2336
2391
  if ( *pEnd == ':' )
2337
2392
  ++pEnd;
2338
-
2393
+
2339
2394
  port = atoi( pEnd );
2340
2395
  if (( port <= 0 )||( port > 65535 ))
2341
2396
  return -1;
@@ -2356,13 +2411,13 @@ int LSAPI_ParseSockAddr( const char * pBind, struct sockaddr * pAddr )
2356
2411
  memcpy(pAddr, res->ai_addr, res->ai_addrlen);
2357
2412
  freeaddrinfo(res);
2358
2413
  }
2359
-
2414
+
2360
2415
  if ( pAddr->sa_family == AF_INET )
2361
2416
  ((struct sockaddr_in *)pAddr)->sin_port = htons( port );
2362
2417
  else
2363
2418
  ((struct sockaddr_in6 *)pAddr)->sin6_port = htons( port );
2364
2419
  return 0;
2365
-
2420
+
2366
2421
  }
2367
2422
 
2368
2423
  int LSAPI_CreateListenSock( const char * pBind, int backlog )
@@ -2408,11 +2463,11 @@ typedef struct _lsapi_prefork_server
2408
2463
  int m_iChildrenMaxIdleTime;
2409
2464
  int m_iMaxReqProcessTime;
2410
2465
  int m_iAvoidFork;
2411
-
2466
+
2412
2467
  lsapi_child_status * m_pChildrenStatus;
2413
2468
  lsapi_child_status * m_pChildrenStatusCur;
2414
2469
  lsapi_child_status * m_pChildrenStatusEnd;
2415
-
2470
+
2416
2471
  }lsapi_prefork_server;
2417
2472
 
2418
2473
  static lsapi_prefork_server * g_prefork_server = NULL;
@@ -2427,7 +2482,7 @@ int LSAPI_Init_Prefork_Server( int max_children, fn_select_t fp, int avoidFork )
2427
2482
  if ( max_children >= 10000)
2428
2483
  max_children = 10000;
2429
2484
 
2430
-
2485
+
2431
2486
  g_prefork_server = (lsapi_prefork_server *)malloc( sizeof( lsapi_prefork_server ) );
2432
2487
  if ( !g_prefork_server )
2433
2488
  return -1;
@@ -2441,14 +2496,14 @@ int LSAPI_Init_Prefork_Server( int max_children, fn_select_t fp, int avoidFork )
2441
2496
  setpgid( pid, pid );
2442
2497
  g_prefork_server->m_iAvoidFork = avoidFork;
2443
2498
  g_prefork_server->m_iMaxChildren = max_children;
2444
-
2499
+
2445
2500
  g_prefork_server->m_iExtraChildren = ( avoidFork ) ? 0 : (max_children / 3) ;
2446
2501
  g_prefork_server->m_iMaxIdleChildren = ( avoidFork ) ? (max_children + 1) : (max_children / 3);
2447
2502
  if ( g_prefork_server->m_iMaxIdleChildren == 0 )
2448
2503
  g_prefork_server->m_iMaxIdleChildren = 1;
2449
2504
  g_prefork_server->m_iChildrenMaxIdleTime = 300;
2450
2505
  g_prefork_server->m_iMaxReqProcessTime = 3600;
2451
- return 0;
2506
+ return 0;
2452
2507
  }
2453
2508
 
2454
2509
  void LSAPI_Set_Server_fd( int fd )
@@ -2552,10 +2607,10 @@ static void lsapi_sigchild( int signal )
2552
2607
 
2553
2608
  }
2554
2609
 
2555
- static int lsapi_init_children_status()
2610
+ static int lsapi_init_children_status(void)
2556
2611
  {
2557
2612
  int size = 4096;
2558
-
2613
+
2559
2614
  char * pBuf;
2560
2615
  size = (g_prefork_server->m_iMaxChildren + g_prefork_server->m_iExtraChildren ) * sizeof( lsapi_child_status ) * 2;
2561
2616
  size = (size + 4095 ) / 4096 * 4096;
@@ -2583,9 +2638,9 @@ static void dump_debug_info( lsapi_child_status * pStatus, long tmCur )
2583
2638
  }
2584
2639
  s_pid_dump_debug_info = fork();
2585
2640
 
2586
- fprintf( stderr, "[%s] Possible runaway process, PPID: %d, PID: %d, reqCount: %d, process time: %ld, checkpoint time: %ld, start time: %ld\n",
2587
- ctime(&tmCur), getpid(), pStatus->m_pid, pStatus->m_iReqCounter,
2588
- tmCur - pStatus->m_tmReqBegin, tmCur - pStatus->m_tmLastCheckPoint, tmCur - pStatus->m_tmStart );
2641
+ fprintf( stderr, "[%s] Possible runaway process, PPID: %d, PID: %d, reqCount: %d, process time: %ld, checkpoint time: %ld, start time: %ld\n",
2642
+ ctime(&tmCur), getpid(), pStatus->m_pid, pStatus->m_iReqCounter,
2643
+ tmCur - pStatus->m_tmReqBegin, tmCur - pStatus->m_tmLastCheckPoint, tmCur - pStatus->m_tmStart );
2589
2644
  snprintf( achCmd, 1024, "gdb --batch -ex \"attach %d\" -ex \"set height 0\" -ex \"bt\" >&2;PATH=$PATH:/usr/sbin lsof -p %d >&2", pStatus->m_pid, pStatus->m_pid );
2590
2645
  if ( system( achCmd ) == -1 )
2591
2646
  perror( "system()" );
@@ -2608,7 +2663,7 @@ static void lsapi_check_child_status( long tmCur )
2608
2663
  ++count;
2609
2664
  if ( !pStatus->m_inProcess )
2610
2665
  {
2611
-
2666
+
2612
2667
  if (( g_prefork_server->m_iCurChildren - dying > g_prefork_server->m_iMaxChildren)||
2613
2668
  ( idle > g_prefork_server->m_iMaxIdleChildren ))
2614
2669
  {
@@ -2628,7 +2683,7 @@ static void lsapi_check_child_status( long tmCur )
2628
2683
  }
2629
2684
  else
2630
2685
  {
2631
- if ( tmCur - pStatus->m_tmReqBegin >
2686
+ if ( tmCur - pStatus->m_tmReqBegin >
2632
2687
  g_prefork_server->m_iMaxReqProcessTime )
2633
2688
  {
2634
2689
  if (( ( pStatus->m_iKillSent % 5 ) == 0 )&&( s_dump_debug_info ))
@@ -2663,13 +2718,13 @@ static void lsapi_check_child_status( long tmCur )
2663
2718
  }
2664
2719
  if ( abs( g_prefork_server->m_iCurChildren - count ) > 1 )
2665
2720
  {
2666
- fprintf( stderr, "Children tracking is wrong: PID: %d, Cur Childen: %d, count: %d, idle: %d, dying: %d\n", getpid(),
2721
+ fprintf( stderr, "Children tracking is wrong: PID: %d, Cur Children: %d, count: %d, idle: %d, dying: %d\n", getpid(),
2667
2722
  g_prefork_server->m_iCurChildren, count, idle, dying );
2668
2723
 
2669
2724
  }
2670
2725
  }
2671
2726
 
2672
- static int lsapi_all_children_must_die()
2727
+ static int lsapi_all_children_must_die(void)
2673
2728
  {
2674
2729
  int maxWait;
2675
2730
  int sec =0;
@@ -2707,7 +2762,7 @@ static int lsapi_prefork_server_accept( lsapi_prefork_server * pServer, LSAPI_Re
2707
2762
  sigset_t orig_mask;
2708
2763
 
2709
2764
  lsapi_init_children_status();
2710
-
2765
+
2711
2766
  setsid();
2712
2767
 
2713
2768
  act.sa_flags = 0;
@@ -2797,17 +2852,17 @@ static int lsapi_prefork_server_accept( lsapi_prefork_server * pServer, LSAPI_Re
2797
2852
 
2798
2853
  sigemptyset( &mask );
2799
2854
  sigaddset( &mask, SIGCHLD );
2800
-
2801
- if ( sigprocmask(SIG_BLOCK, &mask, &orig_mask) < 0 )
2855
+
2856
+ if ( sigprocmask(SIG_BLOCK, &mask, &orig_mask) < 0 )
2802
2857
  {
2803
2858
  perror( "sigprocmask(SIG_BLOCK) to block SIGCHLD" );
2804
2859
  }
2805
2860
 
2806
2861
  pid = fork();
2807
-
2862
+
2808
2863
  if ( !pid )
2809
2864
  {
2810
- if (sigprocmask(SIG_SETMASK, &orig_mask, NULL) < 0)
2865
+ if (sigprocmask(SIG_SETMASK, &orig_mask, NULL) < 0)
2811
2866
  perror( "sigprocmask( SIG_SETMASK ) to restore SIGMASK in child" );
2812
2867
  g_prefork_server = NULL;
2813
2868
  s_ppid = getppid();
@@ -2849,7 +2904,7 @@ static int lsapi_prefork_server_accept( lsapi_prefork_server * pServer, LSAPI_Re
2849
2904
  close( pReq->m_fd );
2850
2905
  pReq->m_fd = -1;
2851
2906
 
2852
- if (sigprocmask(SIG_SETMASK, &orig_mask, NULL) < 0)
2907
+ if (sigprocmask(SIG_SETMASK, &orig_mask, NULL) < 0)
2853
2908
  perror( "sigprocmask( SIG_SETMASK ) to restore SIGMASK" );
2854
2909
 
2855
2910
  }
@@ -2898,7 +2953,7 @@ int LSAPI_Prefork_Accept_r( LSAPI_Request * pReq )
2898
2953
  s_pChildStatus->m_tmWaitBegin = time( NULL );
2899
2954
  }
2900
2955
 
2901
-
2956
+
2902
2957
  while( g_running )
2903
2958
  {
2904
2959
  if ( pReq->m_fd != -1 )
@@ -2917,7 +2972,7 @@ int LSAPI_Prefork_Accept_r( LSAPI_Request * pReq )
2917
2972
  if ( !g_running )
2918
2973
  return -1;
2919
2974
  if ((s_req_processed)&&( s_pChildStatus )&&( s_pChildStatus->m_iKillSent ))
2920
- return -1;
2975
+ return -1;
2921
2976
  FD_ZERO( &readfds );
2922
2977
  FD_SET( fd, &readfds );
2923
2978
  timeout.tv_sec = 1;
@@ -2945,7 +3000,7 @@ int LSAPI_Prefork_Accept_r( LSAPI_Request * pReq )
2945
3000
  else if ( ret >= 1 )
2946
3001
  {
2947
3002
  if (s_req_processed && ( s_pChildStatus )&&( s_pChildStatus->m_iKillSent ))
2948
- return -1;
3003
+ return -1;
2949
3004
  if ( fd == pReq->m_fdListen )
2950
3005
  {
2951
3006
  pReq->m_fd = lsapi_accept( pReq->m_fdListen );
@@ -2993,7 +3048,7 @@ int LSAPI_Prefork_Accept_r( LSAPI_Request * pReq )
2993
3048
  LSAPI_Reset_r( pReq );
2994
3049
  }
2995
3050
  return -1;
2996
-
3051
+
2997
3052
  }
2998
3053
 
2999
3054
  void LSAPI_Set_Max_Reqs( int reqs )
@@ -3038,13 +3093,13 @@ void LSAPI_Set_Slow_Req_Msecs( int msecs )
3038
3093
  s_slow_req_msecs = msecs;
3039
3094
  }
3040
3095
 
3041
- int LSAPI_Get_Slow_Req_Msecs()
3096
+ int LSAPI_Get_Slow_Req_Msecs(void)
3042
3097
  {
3043
3098
  return s_slow_req_msecs;
3044
3099
  }
3045
3100
 
3046
3101
 
3047
- void LSAPI_No_Check_ppid()
3102
+ void LSAPI_No_Check_ppid(void)
3048
3103
  {
3049
3104
  s_ppid = 0;
3050
3105
  }
@@ -3054,7 +3109,7 @@ void LSAPI_No_Check_ppid()
3054
3109
  #else
3055
3110
  extern char ** environ;
3056
3111
  #endif
3057
- static void unset_lsapi_envs()
3112
+ static void unset_lsapi_envs(void)
3058
3113
  {
3059
3114
  char **env;
3060
3115
  #if defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)
@@ -3062,22 +3117,22 @@ static void unset_lsapi_envs()
3062
3117
  #else
3063
3118
  env = environ;
3064
3119
  #endif
3065
- while( env != NULL && *env != NULL )
3120
+ while( env != NULL && *env != NULL )
3066
3121
  {
3067
- if (!strncmp(*env, "LSAPI_", 6) || !strncmp( *env, "PHP_LSAPI_", 10 )
3068
- || (!strncmp( *env, "PHPRC=", 6 )&&(!s_uid)))
3069
- {
3122
+ if (!strncmp(*env, "LSAPI_", 6) || !strncmp( *env, "PHP_LSAPI_", 10 )
3123
+ || (!strncmp( *env, "PHPRC=", 6 )&&(!s_uid)))
3124
+ {
3070
3125
  char ** del = env;
3071
- do
3126
+ do
3072
3127
  *del = del[1];
3073
3128
  while( *del++ );
3074
3129
  }
3075
3130
  else
3076
3131
  ++env;
3077
- }
3132
+ }
3078
3133
  }
3079
3134
 
3080
- static int lsapi_initSuEXEC()
3135
+ static int lsapi_initSuEXEC(void)
3081
3136
  {
3082
3137
  int i;
3083
3138
  struct passwd * pw;
@@ -3101,7 +3156,7 @@ static int lsapi_initSuEXEC()
3101
3156
  }
3102
3157
  p = getenv( "LSAPI_SECRET" );
3103
3158
  if (( !p )||( readSecret(p) == -1 ))
3104
- return -1;
3159
+ return -1;
3105
3160
  if ( g_prefork_server )
3106
3161
  {
3107
3162
  if ( g_prefork_server->m_iMaxChildren < 100 )
@@ -3113,10 +3168,20 @@ static int lsapi_initSuEXEC()
3113
3168
  if ( !s_defaultUid || !s_defaultGid )
3114
3169
  {
3115
3170
  pw = getpwnam( "nobody" );
3116
- if ( !s_defaultUid )
3117
- s_defaultUid = pw->pw_uid;
3118
- if ( !s_defaultGid )
3119
- s_defaultGid = pw->pw_gid;
3171
+ if ( pw )
3172
+ {
3173
+ if ( !s_defaultUid )
3174
+ s_defaultUid = pw->pw_uid;
3175
+ if ( !s_defaultGid )
3176
+ s_defaultGid = pw->pw_gid;
3177
+ }
3178
+ else
3179
+ {
3180
+ if ( !s_defaultUid )
3181
+ s_defaultUid = 10000;
3182
+ if ( !s_defaultGid )
3183
+ s_defaultGid = 10000;
3184
+ }
3120
3185
  }
3121
3186
  return 0;
3122
3187
  }
@@ -3141,7 +3206,7 @@ int LSAPI_Init_Env_Parameters( fn_select_t fp )
3141
3206
  if ( p )
3142
3207
  {
3143
3208
  avoidFork = atoi( p );
3144
- }
3209
+ }
3145
3210
 
3146
3211
  p = getenv( "LSAPI_ACCEPT_NOTIFY" );
3147
3212
  if ( p )
@@ -3150,7 +3215,7 @@ int LSAPI_Init_Env_Parameters( fn_select_t fp )
3150
3215
  }
3151
3216
 
3152
3217
  p = getenv( "LSAPI_SLOW_REQ_MSECS" );
3153
- if ( p )
3218
+ if ( p )
3154
3219
  {
3155
3220
  n = atoi( p );
3156
3221
  LSAPI_Set_Slow_Req_Msecs( n );
@@ -3200,26 +3265,26 @@ int LSAPI_Init_Env_Parameters( fn_select_t fp )
3200
3265
  p = getenv( "LSAPI_EXTRA_CHILDREN" );
3201
3266
  if ( p )
3202
3267
  LSAPI_Set_Extra_Children( atoi( p ) );
3203
-
3268
+
3204
3269
  p = getenv( "LSAPI_MAX_IDLE_CHILDREN" );
3205
3270
  if ( p )
3206
3271
  LSAPI_Set_Max_Idle_Children( atoi( p ) );
3207
-
3272
+
3208
3273
  p = getenv( "LSAPI_PGRP_MAX_IDLE" );
3209
3274
  if ( p )
3210
3275
  {
3211
3276
  LSAPI_Set_Server_Max_Idle_Secs( atoi( p ) );
3212
3277
  }
3213
-
3278
+
3214
3279
  p = getenv( "LSAPI_MAX_PROCESS_TIME" );
3215
- if ( p )
3280
+ if ( p )
3216
3281
  LSAPI_Set_Max_Process_Time( atoi( p ) );
3217
-
3282
+
3218
3283
  if ( getenv( "LSAPI_PPID_NO_CHECK" ) )
3219
3284
  {
3220
3285
  LSAPI_No_Check_ppid();
3221
3286
  }
3222
-
3287
+
3223
3288
  p = getenv( "LSAPI_DUMP_DEBUG_INFO" );
3224
3289
  if ( p )
3225
3290
  s_dump_debug_info = atoi( p );
@@ -3235,7 +3300,7 @@ int LSAPI_Init_Env_Parameters( fn_select_t fp )
3235
3300
  }
3236
3301
 
3237
3302
 
3238
- int LSAPI_ErrResponse_r( LSAPI_Request * pReq, int code, const char ** pRespHeaders,
3303
+ int LSAPI_ErrResponse_r( LSAPI_Request * pReq, int code, const char ** pRespHeaders,
3239
3304
  const char * pBody, int bodyLen )
3240
3305
  {
3241
3306
  LSAPI_SetRespStatus_r( pReq, code );