mirror of
				https://github.com/postgres/postgres.git
				synced 2025-11-03 09:13:20 +03:00 
			
		
		
		
	Replace calls of htonl()/ntohl() with pg_bswap.h for GSSAPI encryption
The in-core equivalents can make use of built-in functions if the compiler supports this option, making optimizations possible.0ba99c8replaced all existing calls in the code base at this time, butb0b39f7(GSSAPI encryption) has forgotten to do the switch. Discussion: https://postgr.es/m/20201014055303.GG3349@paquier.xyz
This commit is contained in:
		@@ -209,7 +209,7 @@ be_gssapi_write(Port *port, void *ptr, size_t len)
 | 
				
			|||||||
		PqGSSSendConsumed += input.length;
 | 
							PqGSSSendConsumed += input.length;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/* 4 network-order bytes of length, then payload */
 | 
							/* 4 network-order bytes of length, then payload */
 | 
				
			||||||
		netlen = htonl(output.length);
 | 
							netlen = pg_hton32(output.length);
 | 
				
			||||||
		memcpy(PqGSSSendBuffer + PqGSSSendLength, &netlen, sizeof(uint32));
 | 
							memcpy(PqGSSSendBuffer + PqGSSSendLength, &netlen, sizeof(uint32));
 | 
				
			||||||
		PqGSSSendLength += sizeof(uint32);
 | 
							PqGSSSendLength += sizeof(uint32);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -323,7 +323,7 @@ be_gssapi_read(Port *port, void *ptr, size_t len)
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/* Decode the packet length and check for overlength packet */
 | 
							/* Decode the packet length and check for overlength packet */
 | 
				
			||||||
		input.length = ntohl(*(uint32 *) PqGSSRecvBuffer);
 | 
							input.length = pg_ntoh32(*(uint32 *) PqGSSRecvBuffer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (input.length > PQ_GSS_RECV_BUFFER_SIZE - sizeof(uint32))
 | 
							if (input.length > PQ_GSS_RECV_BUFFER_SIZE - sizeof(uint32))
 | 
				
			||||||
			ereport(FATAL,
 | 
								ereport(FATAL,
 | 
				
			||||||
@@ -509,7 +509,7 @@ secure_open_gssapi(Port *port)
 | 
				
			|||||||
		/*
 | 
							/*
 | 
				
			||||||
		 * Get the length for this packet from the length header.
 | 
							 * Get the length for this packet from the length header.
 | 
				
			||||||
		 */
 | 
							 */
 | 
				
			||||||
		input.length = ntohl(*(uint32 *) PqGSSRecvBuffer);
 | 
							input.length = pg_ntoh32(*(uint32 *) PqGSSRecvBuffer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/* Done with the length, reset our buffer */
 | 
							/* Done with the length, reset our buffer */
 | 
				
			||||||
		PqGSSRecvLength = 0;
 | 
							PqGSSRecvLength = 0;
 | 
				
			||||||
@@ -567,7 +567,7 @@ secure_open_gssapi(Port *port)
 | 
				
			|||||||
		 */
 | 
							 */
 | 
				
			||||||
		if (output.length > 0)
 | 
							if (output.length > 0)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			uint32		netlen = htonl(output.length);
 | 
								uint32		netlen = pg_hton32(output.length);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (output.length > PQ_GSS_SEND_BUFFER_SIZE - sizeof(uint32))
 | 
								if (output.length > PQ_GSS_SEND_BUFFER_SIZE - sizeof(uint32))
 | 
				
			||||||
				ereport(FATAL,
 | 
									ereport(FATAL,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -226,7 +226,7 @@ pg_GSS_write(PGconn *conn, const void *ptr, size_t len)
 | 
				
			|||||||
		PqGSSSendConsumed += input.length;
 | 
							PqGSSSendConsumed += input.length;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/* 4 network-order bytes of length, then payload */
 | 
							/* 4 network-order bytes of length, then payload */
 | 
				
			||||||
		netlen = htonl(output.length);
 | 
							netlen = pg_hton32(output.length);
 | 
				
			||||||
		memcpy(PqGSSSendBuffer + PqGSSSendLength, &netlen, sizeof(uint32));
 | 
							memcpy(PqGSSSendBuffer + PqGSSSendLength, &netlen, sizeof(uint32));
 | 
				
			||||||
		PqGSSSendLength += sizeof(uint32);
 | 
							PqGSSSendLength += sizeof(uint32);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -346,7 +346,7 @@ pg_GSS_read(PGconn *conn, void *ptr, size_t len)
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/* Decode the packet length and check for overlength packet */
 | 
							/* Decode the packet length and check for overlength packet */
 | 
				
			||||||
		input.length = ntohl(*(uint32 *) PqGSSRecvBuffer);
 | 
							input.length = pg_ntoh32(*(uint32 *) PqGSSRecvBuffer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (input.length > PQ_GSS_RECV_BUFFER_SIZE - sizeof(uint32))
 | 
							if (input.length > PQ_GSS_RECV_BUFFER_SIZE - sizeof(uint32))
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
@@ -589,7 +589,7 @@ pqsecure_open_gss(PGconn *conn)
 | 
				
			|||||||
		 */
 | 
							 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/* Get the length and check for over-length packet */
 | 
							/* Get the length and check for over-length packet */
 | 
				
			||||||
		input.length = ntohl(*(uint32 *) PqGSSRecvBuffer);
 | 
							input.length = pg_ntoh32(*(uint32 *) PqGSSRecvBuffer);
 | 
				
			||||||
		if (input.length > PQ_GSS_RECV_BUFFER_SIZE - sizeof(uint32))
 | 
							if (input.length > PQ_GSS_RECV_BUFFER_SIZE - sizeof(uint32))
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			printfPQExpBuffer(&conn->errorMessage,
 | 
								printfPQExpBuffer(&conn->errorMessage,
 | 
				
			||||||
@@ -688,7 +688,7 @@ pqsecure_open_gss(PGconn *conn)
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Queue the token for writing */
 | 
						/* Queue the token for writing */
 | 
				
			||||||
	netlen = htonl(output.length);
 | 
						netlen = pg_hton32(output.length);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	memcpy(PqGSSSendBuffer, (char *) &netlen, sizeof(uint32));
 | 
						memcpy(PqGSSSendBuffer, (char *) &netlen, sizeof(uint32));
 | 
				
			||||||
	PqGSSSendLength += sizeof(uint32);
 | 
						PqGSSSendLength += sizeof(uint32);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user