{"id":19221201,"url":"https://github.com/gozeloglu/safe_strn","last_synced_at":"2025-02-23T09:26:53.506Z","repository":{"id":74684418,"uuid":"344947149","full_name":"gozeloglu/safe_strn","owner":"gozeloglu","description":"Safe string library for C language.","archived":false,"fork":false,"pushed_at":"2021-03-13T11:35:21.000Z","size":34,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-04T20:16:39.694Z","etag":null,"topics":["buffer-overflow","buffer-overflow-attack","c","c-string","library","string","string-library"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gozeloglu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-03-05T22:12:09.000Z","updated_at":"2024-04-06T22:30:37.000Z","dependencies_parsed_at":"2023-07-25T10:35:18.638Z","dependency_job_id":null,"html_url":"https://github.com/gozeloglu/safe_strn","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gozeloglu%2Fsafe_strn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gozeloglu%2Fsafe_strn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gozeloglu%2Fsafe_strn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gozeloglu%2Fsafe_strn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gozeloglu","download_url":"https://codeload.github.com/gozeloglu/safe_strn/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240295372,"owners_count":19778875,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["buffer-overflow","buffer-overflow-attack","c","c-string","library","string","string-library"],"created_at":"2024-11-09T14:40:27.156Z","updated_at":"2025-02-23T09:26:53.443Z","avatar_url":"https://github.com/gozeloglu.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# safe_strn\n\nsafe_strn is a C library for safe string operation. It includes some basic string functions to prevent buffer overflow.\n\n### Run\n\nFirstly, compile the code with following command:\n\n```shell\n$ gcc lib/*.h lib/*.c test/*.h test/*.c example/*\n```\n\nThen, run the executable file.\n\n```shell\n$ ./a.out\n```\n\n### Usage\n\nAdd `lib/` folder under your workspace and include the library as follows. You may need to give the relative path depending on where you put location.\n\n```c\n#include \"safe_string.h\"\n\nint main() {\n    \n    char *src = \"hello world\";\n    char *new_str = (char *) malloc(sizeof(char) * 12); // Allocate memory for string\n    str_cpy(src, new_str, 11);  // Copy src to new_str\n    \n    int len = str_len(new_str); // Length of new_str\n    \n    char *str1 = \"abc\";\n    char *str2 = \"abc\";\n    int res = str_cmp(str1, str2, 3, 3);\n    \n    if (res \u003c 0) {\n        printf(\"str1 less than str2\\n\"): \n    } else if (res \u003e 0){\n        printf(\"str2 less than str1.\\n\");\n    } else {\n        printf(\"str1 and str2 are equal.\\n\");    // Prints \"str1 and str2 are equal.\"\n    }\n    \n    char *str = str_mk(\"create a new string.\", 50); // Create a null-terminated string with maximum 50 length.\n}\n```\n\n### Documentation\n\n### `str_mk`\nCreates string by preventing potential buffer overflow. Guarantees putting null-terminator at the end of the string. Also, prevents buffer overflow which is caused by integer overflow.\n\n```c\nchar *str_mk(const char *str, size_t str_len);\n```\n\n### `str_cpy`\n\nCopies the string from `src` to `dst`. You need to pass length of the string that you want to copy.\n\n```C\nint str_cpy(const char *src, char *dst, size_t n));\n```\n\n### `str_len` \n\nReturns the length of the string.\n\n```C\nint str_len(const char *s);\n```\n\n### `str_cat` \n\nConcatenates the given strings. Returns the new length of the `src`.\n\n```C\nint str_cat(char *src, const char *append, size_t src_size, size_t app_size);\n```\n\n### `str_cmp` \n\nCompares the two given strings. If `str1` less than `str2`, returns -1. If `str2` less than `str1`, returns 1. And `str1` and `str2` are equal, then returns 0.\n\n```c\nint str_cmp(const char *str1, const char *str2, size_t str1_size, size_t str2_size);\n```\n\n## LICENSE\n[GNU General Public License v3.0](https://github.com/gozeloglu/safe_strn/blob/main/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgozeloglu%2Fsafe_strn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgozeloglu%2Fsafe_strn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgozeloglu%2Fsafe_strn/lists"}