Questions tagged [memory-safety]

Memory safety is a concern in software development that aims to avoid software bugs that cause security vulnerabilities dealing with random-access memory (RAM) access, such as buffer overflows and dangling pointers.

47 questions
54
votes
8 answers

Buffer overflow works in gdb but not without it

I am on CentOS 6.4 32 bit and am trying to cause a buffer overflow in a program. Within GDB it works. Here is the output: [root@localhost bufferoverflow]# gdb stack GNU gdb (GDB) Red Hat Enterprise Linux (7.2-60.el6_4.1) Copyright (C) 2010 Free…
thaweatherman
  • 1,467
  • 4
  • 20
  • 32
48
votes
8 answers

Is Python type safe?

According to Wikipedia Computer scientists consider a language "type-safe" if it does not allow operations or conversions that violate the rules of the type system. Since Python runtime checks ensure that type system rules are satisfied, we should…
user8664060
  • 507
  • 1
  • 4
  • 6
24
votes
1 answer

Quickchecking a nasty foreign function in Haskell(GHC)

I'd like to use Haskell's quickcheck library test some C code. The easiest way seems to be doing a foreign import and write a property on top of the resulting haskell function. The problem with this is that if the C code causes a segfault or…
aleator
  • 4,436
  • 20
  • 31
22
votes
2 answers

weak vs unowned in Swift. What are the internal differences?

I understand the usage and superficial differences between weak and unowned in Swift: The simplest examples I've seen is that if there is a Dog and a Bone, the Bone may have a weak reference to the Dog (and vice versa) because the each can exist…
ephemer
  • 1,239
  • 8
  • 21
21
votes
2 answers

What does it take to write memory safe C++ applications?

Is it possible to either create a coding standard or use of a library that can be proved to eliminate any memory management errors in C++? I'm thinking of something like Java, it is just impossible to for example have dangling pointers in Java…
Jesus H
  • 1,180
  • 3
  • 13
  • 25
17
votes
3 answers

How does Rust achieve compile-time-only pointer safety?

I have read somewhere that in a language that features pointers, it is not possible for the compiler to decide fully at compile time whether all pointers are used correctly and/or are valid (refer to an alive object) for various reasons, since that…
11
votes
1 answer

Alternatives to dynamic allocations in safety critical projects (C)

Safety critical projects do not recommend any dynamic allocations or freeing allocated memory. Only during elaboration/initialization phase of the program execution, it is allowed. I know most of you will argue to implement SW in terms where it…
Akay
  • 1,092
  • 12
  • 32
10
votes
1 answer

Is Python memory-safe?

With Deno being the new Node.js rival and all, the memory-safe nature of Rust has been mentioned in a lot of news articles, one particular piece stated Rust and Go are good for their memory-safe nature, as are Swift and Kotlin but the latter two are…
qedk
  • 468
  • 6
  • 18
10
votes
3 answers

Clarify the meaning of binding two references to differently scoped referents to the same lifetime in a function signature

I've been trying to get my head around the Rust borrowing and ownership model. Suppose we have the following code: fn main() { let a = String::from("short"); { let b = String::from("a long long long string"); println!("{}",…
Edd Barrett
  • 3,425
  • 2
  • 29
  • 48
8
votes
2 answers

Why are borrows of struct members allowed in &mut self, but not of self to immutable methods?

If I have a struct that encapsulates two members, and updates one based on the other, that's fine as long as I do it this way: struct A { value: i64 } impl A { pub fn new() -> Self { A { value: 0 } } pub fn do_something(&mut…
Leonora Tindall
  • 1,391
  • 2
  • 12
  • 30
6
votes
1 answer

What is an efficient equivalent in C# for Span>, which does not exist?

I was porting some older high-speed C++ code to C#, and the existing code made use of a pointer-based double-indirection pattern like this (written here in a C# syntax), using the stack as efficient temporary storage: public struct Source { …
Sean Werkema
  • 5,810
  • 2
  • 38
  • 42
5
votes
1 answer

Ownership tracking in Rust: Difference between Box (heap) and T (stack)

Experimenting with the programming language Rust, I found that the compiler is able to track a move of a field of some struct on the stack very accurately (it knows exactly what field has moved). However, when I put one part of the structure into a…
domin
  • 1,192
  • 1
  • 7
  • 28
5
votes
1 answer

How can I manually zero out memory?

Is it possible to manually clear out the contents of an object from memory? In particular, I'm dealing with NSData. I've tried using data.length = 0 and data.setData(NSData). I know ARC will come in and clean up after it is out of scope to whom it…
David Biga
  • 2,763
  • 8
  • 38
  • 61
4
votes
2 answers

Is there a C++ warning for returning a reference into a temporary?

There's an error for this case: const int& foo() { const int x = 0; return x; } and even const int& foo() { const std::pair x = {0,0}; return x.first; } but not this: const int& foo() { const std::array x =…
Ben
  • 9,184
  • 1
  • 43
  • 56
4
votes
1 answer

Memory safety in swift (inout param/long term access)

I was reading the memory safety chapter in swift, and wanted to try this exemple : var stepSize = 1 func increment(_ number: inout Int) { number += stepSize } increment(&stepSize) Event if it says that there is an error because of the…
user509981
1
2 3 4