Skip to content

Use an int instead of a char for strlen

The C character IO functions use an int for most operations, so the type should be int for fgetc.

And the variable 'c' is reused to store the strlen() result. Using a char type for strlen resulted in negative values whenever a header line was longer than 127 bytes.

Here is a sample header line that caused problems: x-microsoft-antispam-message-info: aybxZFQCLkTSg3dcgJ5/htFKWNjG+YSDDv+nSqJhvcMwb2hnzVKN1KQn0G0vxYRF7D1aWmkCcHUBLLWq/szFtrbKQ3BvDyr8nRMpr8jVkfWPpXt2np7eZDBBm4pU/TvGa+D8n+YUALZRs+9JliL3TzP8d2LRFDWhGKAQXl/FXwpzBq8mv+hxIiUYBHn0IxdJA1gJIxAZms1tqzec9XLV8sLrPDL0Hu2rHnGbCJLIphSC0abIOH1VTEEdzkbXhS8aSk6636GkCI1f2fN9PVNMj9uWzfIM1gSOeJyro6lQxREwwLMqnLGsf44OEKsqfCsh3yrOixdSBMWx09f3xJVgQBQOovwLCF7INvX6Oexzd8eA8YoHGp/01qVP4cPdd7W2TbxFlK8nMFmjuXdCyw/4If+dJu+uKpMQ2vh69jR7XWg=

After that, 'c' was negative and resulted in reads and writes into unallocated memory and finally a segmentation fault.

Merge request reports