• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

NVIDIA / nvrc / 20284408377

16 Dec 2025 10:13PM UTC coverage: 50.277% (+13.5%) from 36.748%
20284408377

push

github

web-flow
Merge pull request #78 from zvonkok/main

Refactor NVRC to be more Rust Idiomatic

340 of 555 new or added lines in 30 files covered. (61.26%)

12 existing lines in 4 files now uncovered.

544 of 1082 relevant lines covered (50.28%)

0.78 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.33
/src/coreutils.rs
1
// SPDX-License-Identifier: Apache-2.0
2
// Copyright (c) NVIDIA CORPORATION
3

4
use anyhow::{Context, Result};
5
use nix::fcntl::AT_FDCWD;
6
use nix::sys::stat::{self, Mode, SFlag};
7
use nix::unistd::symlinkat;
8
use std::fs;
9
use std::path::Path;
10

11
/// Create (or update) a symbolic link from target to linkpath.
12
/// Idempotent: if link already points to target, it is left unchanged.
13
pub fn ln(target: &str, linkpath: &str) -> Result<()> {
1✔
14
    if let Ok(existing) = fs::read_link(linkpath) {
3✔
15
        if existing == Path::new(target) {
2✔
16
            return Ok(());
1✔
17
        }
UNCOV
18
        let _ = fs::remove_file(linkpath);
×
19
    }
20

21
    // If path exists as non-symlink (file/dir), symlinkat will fail.
22
    // INTENTIONAL: in ephemeral VMs, obstacles indicate tampering/compromise.
23
    // Fail loudly rather than silently fixing potentially malicious state.
24
    symlinkat(target, AT_FDCWD, linkpath).with_context(|| format!("ln {} -> {}", linkpath, target))
6✔
25
}
26

27
/// Create (or replace) a character device node with desired major/minor.
28
/// Always recreates to avoid stale metadata/permissions.
29
pub fn mknod(path: &str, kind: SFlag, major: u64, minor: u64) -> Result<()> {
1✔
30
    if Path::new(path).exists() {
1✔
31
        fs::remove_file(path).with_context(|| format!("remove {} failed", path))?;
×
32
    }
33
    stat::mknod(
34
        path,
35
        kind,
36
        Mode::from_bits_truncate(0o666),
1✔
37
        stat::makedev(major, minor),
1✔
38
    )
39
    .with_context(|| format!("mknod {} failed", path))
1✔
40
}
41

42
#[cfg(test)]
43
mod tests {
44
    use super::*;
45
    use tempfile::TempDir;
46

47
    #[test]
48
    fn test_ln_fails_on_regular_file_obstacle() {
49
        // Security test: ln should FAIL if non-symlink obstacle exists
50
        // In ephemeral VMs, this indicates tampering
51
        let tmpdir = TempDir::new().unwrap();
52
        let linkpath = tmpdir.path().join("stdin");
53
        let target = "/proc/self/fd/0";
54

55
        // Create regular file obstacle (simulates tampering)
56
        fs::write(&linkpath, "tampered").unwrap();
57
        assert!(linkpath.exists() && !linkpath.is_symlink());
58

59
        // ln should FAIL (not silently fix)
60
        let result = ln(target, linkpath.to_str().unwrap());
61
        assert!(result.is_err(), "ln must fail on non-symlink obstacle");
62
    }
63

64
    #[test]
65
    fn test_ln_fails_on_directory_obstacle() {
66
        // Security test: ln should FAIL if directory obstacle exists
67
        let tmpdir = TempDir::new().unwrap();
68
        let linkpath = tmpdir.path().join("stdin");
69
        let target = "/proc/self/fd/0";
70

71
        // Create directory obstacle
72
        fs::create_dir(&linkpath).unwrap();
73
        assert!(linkpath.is_dir());
74

75
        // ln should FAIL (not silently fix)
76
        let result = ln(target, linkpath.to_str().unwrap());
77
        assert!(result.is_err(), "ln must fail on directory obstacle");
78
    }
79

80
    #[test]
81
    fn test_ln_idempotent() {
82
        // Verify correct symlinks are left unchanged
83
        let tmpdir = TempDir::new().unwrap();
84
        let linkpath = tmpdir.path().join("test_link");
85
        let target = "/proc/self/fd/0";
86

87
        // Create correct symlink
88
        ln(target, linkpath.to_str().unwrap()).unwrap();
89
        assert!(linkpath.is_symlink());
90

91
        // Call again - should be idempotent
92
        ln(target, linkpath.to_str().unwrap()).unwrap();
93
        assert_eq!(fs::read_link(&linkpath).unwrap(), Path::new(target));
94
    }
95
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc