After two days of testing I can testify that Sorin's analysis is correct. 
Sometimes Apache points to a user-agent string, sometimes it points to a null 
string, and sometimes there is a null pointer.

The reason nothing appeared in the logs is because the requests coming in with 
empty user-agent headers were going to the default server, not to one of the 
named vhosts. The default server returns 410 on everything and logs nothing. 
The test module should not have been active on the default server, but it is a 
good thing it was; this would have been wretched if it had gone to the field 
with that bug.

For future reference to anyone dealing with the user-agent string, here is the 
code I adopted which handles all three possibilities. It is streamlined from 
the original version and no longer copies the user-agent string to local 
storage. This allows the CRC and DJB2 routines to process the entire string and 
not a length-limited substring.


size_t ualength;
const unsigned char* uastring;

...
...

 /* Retrieve the user-agent string */

 uastring = apr_table_get(r->headers_in, "User-Agent");

 /* If there is no user-agent string, the CRC/DJB2 defaults to xFFFFFFFF/x0 */

 ua_crc = 0xFFFFFFFF;
 ua_djb = 0x0;

 /* If the user-agent string is empty, the CRC/DJB2 defaults to x0/xFFFFFFFF. */

 if (uastring != NULL) {
 ua_crc = 0x0;
 ua_djb = 0xFFFFFFFF;
 ualength = strlen(uastring);

 /* If user-agent string exists, compute the CRC-32 and DJB2 hash */

 if (ualength != 0) {
 ua_crc = bc_crc_32(r, bc_scfg, uastring, ualength);
 ua_djb = bc_djb2hash(r, bc_scfg, uastring, ualength);
 }
 }


My thanks to everyone who commented on the problem. I would not have found the 
issue without assistance.

     On Tuesday, 26 October 2021, 07:59:04 am GMT+1, Sorin Manolache 
<sor...@gmail.com> wrote:  
 
 On 26/10/2021 08.18, miim wrote:
> ua_pointer = apr_table_get(r->headers_in, "User-Agent");
>        /* Find out how long the Apache-supplied string is */
>    ualength = strlen(ua_pointer);

If the request does not contain any user-agent then ua_pointer will be 
NULL. strlen of NULL will segfault.

S
  

Reply via email to