In C (at least) local string variables are allocated in the .rodata section or .data segment generally. Why not store them on the stack, since it is a local variable? Will the string data be in memory for the full execution time? Is that not a waste of memory? Answer How have you drawn the conclusion that str…
Tag: c++
If I compile a C/C++ program on a linux machine, does it automatically have rwx perms
I am currently learning penetration testing as part of a cybersecurity career path. I was working on a vulnhub machine that required me writing some malware to exploit a buffer overflow bug. I decided to write it in C for the sake of practicing OpSec. I used code::blocks on my machine to write the code and us…
Futex and pthreads issue
I’m testing futexes with pthreads. I’ve written following program: And sometimes it returns 0 as a sum which is proper value but sometimes the returned value of sum is different than 0. My question is why the returned values of “sum” are different than 0? I suspect that there is someth…
trying to cause SIGSEGV in mmap
I’m trying to create a memory mapping of length greater than the underlying file. When I access pages of the mapping (which are not correspondingly mapped to a file), a SIGBUS is caused. However when I try to access the memory outside the memory mapping length, it should cause SIGSEGV (but isn’t),…
Deplying a C++ application on Linux- linking everything statically to simplify deployment?
I am building a C++ project from Github and want to deploy the code to a remote Linux machine. This is all new to me. The project has a main.cpp, which includes the various headers/sources like a library. The CMake outputs an executable (to represent main.cpp) AND a separate static library. The project also u…
What is the true getrusage resolution?
I’m trying to measure getrusage resolution via simple program: And when I run it, I usually get output similar to the following: ema@scv:~/tmp/getrusage$ ./gt u:0.000562 uz:0.000563 cnt:1 ema@scv:~/tmp/getrusage$ ./gt u:0.000553 uz:0.000554 cnt:1 ema@scv:~/tmp/getrusage$ ./gt u:0.000496 uz:0.000497 cnt:…
Writing a small file blocks for 20 ms
I discovered that on my Ubuntu 22 server, attempting to write to a file, often induces around 20ms delay, even when only writing a few bytes. Here is some basic code that demonstrates the problem: And here is the output: It seems more likely to happen if there is a bit of delay between attempts, and also more…
Writing into a device file prints “Invalid argument”
I am currently working on a device driver where I want to write a sentence to that driver and display it in the kernel. Reading an internal buffer and calling the driver with cat works perfectly fine. However, if I try to write to the device driver it returns the following message: I have the following code f…
Idiomatic way to handle signals in a shared library
I have a shared library that occasionally throws SIGSEGV by design. I can find out if a SIGSEGV is caused by me, and if it is then handle it. However I ran into some problems when implementing the other branch (ie. when it isn’t my SIGSEGV). My primary problem is what if a handler was set to SIG_DFL. Th…
Any possibilities that makefile can use different compilers by flag and find variable gcc paths?
Are there any possibilities that makefile can use different compilers by flag and find variable gcc paths? System is Linux. So the goal should be anything like to say in command line “make CC=…” and it should use one of two possible compilers and should find the path to the second one (first…