unit3214.c (3461B)
1 /*************************************************************************** 2 * _ _ ____ _ 3 * Project ___| | | | _ \| | 4 * / __| | | | |_) | | 5 * | (__| |_| | _ <| |___ 6 * \___|\___/|_| \_\_____| 7 * 8 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 9 * 10 * This software is licensed as described in the file COPYING, which 11 * you should have received as part of this distribution. The terms 12 * are also available at https://curl.se/docs/copyright.html. 13 * 14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell 15 * copies of the Software, and permit persons to whom the Software is 16 * furnished to do so, under the terms of the COPYING file. 17 * 18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 19 * KIND, either express or implied. 20 * 21 * SPDX-License-Identifier: curl 22 * 23 ***************************************************************************/ 24 #include "unitcheck.h" 25 26 #include "urldata.h" 27 28 static void checksize(const char *name, size_t size, size_t allowed) 29 { 30 if(size > allowed) { 31 fprintf(stderr, "BAD: struct %s is %d bytes, allowed to be %d", 32 name, (int)size, (int)allowed); 33 fprintf(stderr, ": %d bytes too big\n", (int)(size - allowed)); 34 unitfail++; 35 } 36 else { 37 printf("FINE: struct %s is %d bytes, allowed %d (margin: %d bytes)\n", 38 name, (int)size, (int)allowed, (int)(allowed - size)); 39 } 40 } 41 42 /* the maximum sizes we allow specific structs to grow to */ 43 #define MAX_CURL_EASY 5800 44 #define MAX_CONNECTDATA 1300 45 #define MAX_CURL_MULTI 750 46 #define MAX_CURL_HTTPPOST 112 47 #define MAX_CURL_SLIST 16 48 #define MAX_CURL_KHKEY 24 49 #define MAX_CURL_HSTSENTRY 40 50 #define MAX_CURL_INDEX 16 51 #define MAX_CURL_MIME 96 52 #define MAX_CURL_MIMEPART 440 53 #define MAX_CURL_CERTINFO 16 54 #define MAX_CURL_TLSSESSIONINFO 16 55 #define MAX_CURL_BLOB 24 56 #define MAX_CURLMSG 24 57 #define MAX_CURL_HEADER 48 58 59 static CURLcode test_unit3214(char *arg) 60 { 61 UNITTEST_BEGIN_SIMPLE 62 63 checksize("Curl_easy", sizeof(struct Curl_easy), MAX_CURL_EASY); 64 checksize("connectdata", sizeof(struct connectdata), MAX_CONNECTDATA); 65 checksize("Curl_multi", sizeof(struct Curl_multi), MAX_CURL_MULTI); 66 67 /* public structs MUST NOT change (unless controlled), but exact sizes 68 depend on architecture */ 69 checksize("curl_httppost", sizeof(struct curl_httppost), MAX_CURL_HTTPPOST); 70 checksize("curl_slist", sizeof(struct curl_slist), MAX_CURL_SLIST); 71 checksize("curl_khkey", sizeof(struct curl_khkey), MAX_CURL_KHKEY); 72 checksize("curl_hstsentry", sizeof(struct curl_hstsentry), 73 MAX_CURL_HSTSENTRY); 74 checksize("curl_index", sizeof(struct curl_index), MAX_CURL_INDEX); 75 checksize("curl_mime", sizeof(struct curl_mime), MAX_CURL_MIME); 76 checksize("curl_mimepart", sizeof(struct curl_mimepart), MAX_CURL_MIMEPART); 77 checksize("curl_certinfo", sizeof(struct curl_certinfo), MAX_CURL_CERTINFO); 78 checksize("curl_tlssessioninfo", sizeof(struct curl_tlssessioninfo), 79 MAX_CURL_TLSSESSIONINFO); 80 checksize("curl_blob", sizeof(struct curl_blob), MAX_CURL_BLOB); 81 checksize("CURLMsg", sizeof(struct CURLMsg), MAX_CURLMSG); 82 checksize("curl_header", sizeof(struct curl_header), MAX_CURL_HEADER); 83 84 UNITTEST_END_SIMPLE 85 }