diff options
| author | avx0 <[email protected]> | 2024-05-29 15:00:28 +0530 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-05-29 11:30:28 +0200 |
| commit | 9cc7e3528f37dd17c85334c16dffb9392b8a6ad2 (patch) | |
| tree | 4b61919d5eb24382651f25443469cff1e1bd0b7a /parser | |
| parent | 785ec74b92da4f91181ff7b1c89c8ae5ee19f1b6 (diff) | |
| download | raylib-9cc7e3528f37dd17c85334c16dffb9392b8a6ad2.tar.gz raylib-9cc7e3528f37dd17c85334c16dffb9392b8a6ad2.zip | |
[parser] MemoryCopy() calls: Prevent buffer overflow by replacing hard-coded arguments (#4011)
In future, if a dev edits the second arg and miscalulates the corresponding 3rd arg, there will be a buffer overflow or the string (2nd arg) will be cut short. This commit prevents that.
Diffstat (limited to 'parser')
| -rw-r--r-- | parser/raylib_parser.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/parser/raylib_parser.c b/parser/raylib_parser.c index 3e36f41f..63f95728 100644 --- a/parser/raylib_parser.c +++ b/parser/raylib_parser.c @@ -202,9 +202,12 @@ int main(int argc, char* argv[]) { if (argc > 1) ProcessCommandLine(argc, argv); - if (inFileName[0] == '\0') MemoryCopy(inFileName, "../src/raylib.h\0", 16); - if (outFileName[0] == '\0') MemoryCopy(outFileName, "raylib_api.txt\0", 15); - if (apiDefine[0] == '\0') MemoryCopy(apiDefine, "RLAPI\0", 6); + const char *raylibhPath = "../src/raylib.h\0"; + const char *raylibapiPath = "raylib_api.txt\0"; + const char *rlapiPath = "RLAPI\0"; + if (inFileName[0] == '\0') MemoryCopy(inFileName, raylibhPath, TextLength(raylibhPath) + 1); + if (outFileName[0] == '\0') MemoryCopy(outFileName, raylibapiPath, TextLength(raylibapiPath) + 1); + if (apiDefine[0] == '\0') MemoryCopy(apiDefine, rlapiPath, TextLength(rlapiPath) + 1); int length = 0; char *buffer = LoadFileText(inFileName, &length); @@ -1277,8 +1280,10 @@ static void GetDataTypeAndName(const char *typeName, int typeNameLen, char *type } else if ((typeName[k] == '.') && (typeNameLen == 3)) // Handle varargs ...); { - MemoryCopy(type, "...", 3); - MemoryCopy(name, "args", 4); + const char *varargsDots = "..."; + const char *varargsArg = "args"; + MemoryCopy(type, varargsDots, TextLength(varargsDots)); + MemoryCopy(name, varargsArg, TextLength(varargsArg)); break; } } |
