Skip to content

[Bug/Testing]: Add positive signal validation in kill.go and unit tests for parseSignal #917

Description

@ParthMozarkar

Summary

In cmd/urunc/kill.go, parseSignal(rawSignal string) handles signal arguments for container termination (e.g. urunc kill <container-id> [signal]).

When a numeric signal string is parsed via strconv.Atoi, non-positive integers (such as 0 or -1) are currently accepted without range validation and directly cast to unix.Signal(s). In POSIX systems, signal 0 is a null signal used for checking process existence rather than killing processes, and negative signal values are invalid for urunc kill.

Additionally, the cmd/urunc package currently lacks unit test coverage for signal parsing logic.

Expected Behavior

  1. parseSignal should validate that numeric signals are strictly positive integers (> 0) and return a descriptive error when s <= 0.
  2. cmd/urunc should have unit test coverage for parseSignal verifying both valid named/numeric signals and invalid inputs.

Proposed Changes

  • Update parseSignal in cmd/urunc/kill.go to add if s <= 0 range validation.
  • Create cmd/urunc/kill_test.go with table-driven tests covering valid named signals (SIGKILL, KILL, kill, SIGTERM), valid numeric signals (9, 15), and invalid inputs (0, -1, unknown signal strings).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions