I have seen people writing plugins pass incorrect locations to APIs. For example you can pass a client request header to an API that wants the url without any errors from the compiler.

Looking at the three APIs below it is hard to tell the location/offset really point to:

tsapi TSReturnCode TSHttpTxnClientReqGet(TSHttpTxn txnp, TSMBuffer* bufp, TSMLoc* offset); tsapi TSReturnCode TSHttpHdrUrlGet(TSMBuffer bufp, TSMLoc offset, TSMLoc* locp); tsapi const char* TSUrlSchemeGet(TSMBuffer bufp, TSMLoc offset, int *length);

In a specific case that happened last week a person was taking bufp and offset from TSHttpTxnClientReqGet() and passing the values to TSUrlSchemeGet(). Since it didn't give him compile errors he only saw the problem when the server was under load and it would core dump.

One way to fix this would be to change locations to specific types. If we want to take it a step further the buffer and location could be combined and given a specific type simplifying the APIs.

Example of changing to specific location types:
tsapi TSReturnCode TSHttpTxnClientReqGet(TSHttpTxn txnp, TSMBuffer* bufp, TSMRequestLoc* offset); tsapi TSReturnCode TSHttpHdrUrlGet(TSMBuffer bufp, TSMRequestLoc offset, TSMUrlLoc* locp); tsapi const char* TSUrlSchemeGet(TSMBuffer bufp, TSMUrlLoc offset, int *length);

Example of combining buffer and location and making specific types (IMO cleaner): tsapi TSReturnCode TSHttpTxnClientReqGet(TSHttpTxn txnp, TSRequest *request);
  tsapi TSReturnCode TSHttpHdrUrlGet(TSRequest request, TSUrl *url);
  tsapi const char* TSUrlSchemeGet(TSUrl url, int *length);

-Bryan

Reply via email to