maandree / slibc Goto Github PK
View Code? Open in Web Editor NEWYet another C standard library
Home Page: https://codeberg.org/maandree/slibc
License: GNU General Public License v3.0
Yet another C standard library
Home Page: https://codeberg.org/maandree/slibc
License: GNU General Public License v3.0
NAME slibc - the Stockholm C Standard Library DESCRIPTION slibc is a POSIX C standard library. It aims to support ISO C99, and newer versions of ISO C, other versions of C are ignored except for proper feature-test macros. Ignores all languages other than C, this means that slibc cannot be used in C++ by merely including the header files. In addition to POSIX, slibc aims to support common extensions, especially those in the GNU C Library because of its predominance on GNU systems. slibc also aims to fill the lacunæ in the C standard library specification, and make programming in C even easier by adding functions that would be generally useful are impossible to implement efficiently in other libraries. FEATURE-TEST MACROS slibc defines a few slibc-specified feature-test macros: _SLIBC_SOURCE Enable slibc extensions. These extensions are often extensions introduced in other C libraries, but are considered good extensions. slibc provides some slibc-specific extensions that do not require _SLIBC_SOURCE. (They are however disabled if _PORTABLE_SOURCE or _LIBRARY_HEADER are defined.) These extensions are defined in header files whose name starts with 'slibc-'. Headers starting with 'slibc/' are not extensions, those are internals that may change at any time. _SLIBC_SUPPRESS_WARNINGS Suppress all #warning and other warnings, this is primarily intended to be used when compiling slibc. _PORTABLE_SOURCE Unconditionally disable all non-POSIX extensions, and otherwise help ensure that the source is portable. _LIBRARY_HEADER Alternative to _PORTABLE_SOURCE that should be used in header files for libraries. This allows you to be sure that your library is portable between libc:s, and that sources using your library does not been to be compiled with the same libc. It is important to use this instead of _PORTABLE_SOURCE in library header files, otherwise the user of the library cannot fully utilise _PORTABLE_SOURCE. COMMENTS Writing a C standard library is a massive task. As I only have x86_64 hardware, I will require help write the assembly code for other hardware. I also need help writing the texinfo manual and example code for functions, help figuring out the correct feature-test macros for all functions, their etymology, and in which libc implementions they appear. Help optimising all functions would also be appreciated. FUTURE DIRECTIONS The macro _SMALL_BINARY shall whenever available, create macros that make the program use implementions of the functions that optimised for size rather than performance. It should be compile-time selectable whether this macro has any effect, or if it is always in effect. _FAST_BINARY could also be added to make the program use fast implementions when the library is compiled to use the size optimised implementations. RATIONALE slibc is written as a learning exercise, and for fun. SEE ALSO <https://en.wikipedia.org/wiki/C_standard_library> Full documentation available locally via: info '(slibc)'
Memory allocated for pathname is lost to execve(). execve() is not aware of the origins of path. Perhaps @param path The pathname of the file to execute.
should clarify that the function will eventually purge the contents of the path parameter, if that's possible.
Storing the results of execve(pathname, argv, envp);
is probably easier.
Please initialize m in humansize_exact().
Hi,
Although this project seems inactive, I felt it would be a good idea to bring this up anyway.
There are two security problems with the wcsndup()
function as implemented here:
maxlen
n * sizeof(wchar_t)
can overflow, causing the buffer to be too small. The result is a possible buffer overrun with wmemcpy()
.The fixes are simple:
calloc()
instead of malloc()
, which should correctly check for overflow (although I've not looked at the implementation in slibc, or checked if there is one) and then return NULL
, or at least shouldwmemcpy()
should copy n - 1
bytes, which means only the actual string contents will be copied. But this is okay, because using calloc()
means the final byte will always L'\0'
.if (signal(SIGSEGV, Sold_sigsegv_handler) == SIG_ERR)
should be if (signal(SIGSEGV, old_sigsegv_handler) == SIG_ERR)
.
Does (RAND_MAX + 1) have the potential to overflow?
it must not compute strlen(haystack)
char haystack[] = { 'A', 'A', ...... 10GB ...... 'A', 0 },
needle[] = { 'A', 0 };
char *ptr = strstr(haystack, needle); // takes ages
and allocating a buffer as large as (or in this case, 8 times larger than) the needle withalloca
is an amazingly bad idea
malloc() failure?
absref = malloc((p + 1) + sizeof(char));
sysconf() may return -1. The long return value should be queried before being used.
In some instances, the function returns -1.
Please see the comment.
if (absref == NULL)
{
p = strlen(cwd);
absref = malloc((p + 1) + sizeof(char)); // Addition or multiplication?
if (absref == NULL)
goto fail;
memcpy(absref, cwd, p);
absref[p] = '/';
absref[p + 1] = '\0';
}
else
strrchr(absref, '/')[1] = '\0';
Should return *(uint16_t*)rc;
be return *(uint32_t*)rc;
?
Division by zero?
Should ptr be checked against MAP_FAILED (mmap() failure)?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.