Project

General

Profile

mod_cgi_c.patch

kahic, 2011-03-12 13:57

View differences:

lighttpd-1.4.26-mod/src/mod_cgi.c 2011-03-12 11:18:11.000000000 +0100
766 766
		char *c;
767 767
		const char *s;
768 768
		server_socket *srv_sock = con->srv_socket;
769
		server_socket dummy;
770
		if (!srv_sock) {
771
			srv_sock= &dummy;
772
			log_error_write(srv, __FILE__, __LINE__, "s", "(debug) Problem: No server socket");
773
		}
769 774

  
770 775
		/* move stdout to from_cgi_fd[1] */
771 776
		close(STDOUT_FILENO);
......
808 813
#else
809 814
			s = inet_ntoa(srv_sock->addr.ipv4.sin_addr);
810 815
#endif
811
			cgi_env_add(&env, CONST_STR_LEN("SERVER_NAME"), s, strlen(s));
816
			if (s)
817
				cgi_env_add(&env, CONST_STR_LEN("SERVER_NAME"), s, strlen(s));
812 818
		}
813 819
		cgi_env_add(&env, CONST_STR_LEN("GATEWAY_INTERFACE"), CONST_STR_LEN("CGI/1.1"));
814 820

  
815 821
		s = get_http_version_name(con->request.http_version);
816 822

  
817
		cgi_env_add(&env, CONST_STR_LEN("SERVER_PROTOCOL"), s, strlen(s));
823
		if (s)
824
			cgi_env_add(&env, CONST_STR_LEN("SERVER_PROTOCOL"), s, strlen(s));
818 825

  
819 826
		LI_ltostr(buf,
820 827
#ifdef HAVE_IPV6
......
846 853
			s = "";
847 854
			break;
848 855
		}
849
		cgi_env_add(&env, CONST_STR_LEN("SERVER_ADDR"), s, strlen(s));
856
		if (s)
857
			cgi_env_add(&env, CONST_STR_LEN("SERVER_ADDR"), s, strlen(s));
850 858

  
851 859
		s = get_http_method_name(con->request.http_method);
852
		cgi_env_add(&env, CONST_STR_LEN("REQUEST_METHOD"), s, strlen(s));
860
		if (s)
861
			cgi_env_add(&env, CONST_STR_LEN("REQUEST_METHOD"), s, strlen(s));
853 862

  
854 863
		if (!buffer_is_empty(con->request.pathinfo)) {
855 864
			cgi_env_add(&env, CONST_STR_LEN("PATH_INFO"), CONST_BUF_LEN(con->request.pathinfo));
......
884 893
			s = "";
885 894
			break;
886 895
		}
887
		cgi_env_add(&env, CONST_STR_LEN("REMOTE_ADDR"), s, strlen(s));
896
		if (s)
897
			cgi_env_add(&env, CONST_STR_LEN("REMOTE_ADDR"), s, strlen(s));
888 898

  
889 899
		LI_ltostr(buf,
890 900
#ifdef HAVE_IPV6
......
1028 1038
		/* exec the cgi */
1029 1039
		execve(args[0], args, env.ptr);
1030 1040

  
1031
		/* log_error_write(srv, __FILE__, __LINE__, "sss", "CGI failed:", strerror(errno), args[0]); */
1041
		log_error_write(srv, __FILE__, __LINE__, "sss", "CGI failed:", strerror(errno), args[0]);
1032 1042

  
1033 1043
		/* */
1044
#if 0
1034 1045
		SEGFAULT();
1046
#endif
1047
		exit(1);
1035 1048
		break;
1036 1049
	}
1037 1050
	case -1: