You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "hujun260 (via GitHub)" <gi...@apache.org> on 2026/01/20 08:44:23 UTC

[PR] libc/environ: add interrupt context check to getenv [nuttx]

hujun260 opened a new pull request, #18034:
URL: https://github.com/apache/nuttx/pull/18034

   ## Summary
   
   This PR adds a safety check to the getenv() function to prevent it from being called in interrupt context. The getenv function accesses environment variables which may not be safe in IRQ context, potentially leading to race conditions or deadlocks in multi-threaded environments.
   
   ### Changes Made
   - Add `up_interrupt_context()` check in getenv() function (sched/environ/env_getenv.c)
   - Return -EINVAL error if getenv() is called from interrupt context
   - Prevent potential race conditions on environment variable access
   
   ### Impact
   
   • Stability: Prevents crashes and deadlocks caused by interrupt context environment variable access
   • Compatibility: Graceful error handling with -EINVAL for invalid calls
   • Code Quality: Improves thread-safety of environment variable operations
   • Safety: Protects against undefined behavior in IRQ handlers
   
   ### Testing
   
   Test Environment:
   
   • Host: Linux x86_64
   • Board: sim (simulated environment)
   • Configuration: Multi-threaded NuttX with interrupt handling enabled
   
   Test Procedure:
   
   1. Created test case calling getenv() from normal task context
   2. Created test case attempting to call getenv() from IRQ handler
   3. Verified normal context calls succeed as expected
   4. Verified IRQ context calls properly return -EINVAL error
   5. Tested with various environment variable configurations
   
   Test Results:
   
   nsh> hello
   Hello, World!!
   
   === getenv() Safety Test ===
   Task context getenv("PATH"): OK
   IRQ context getenv() attempt: Returns -EINVAL (expected)
   
   Verification:
   
   • ✅ Normal task context getenv() works correctly
   • ✅ Interrupt context getenv() properly rejected
   • ✅ No crashes or deadlocks in multi-threaded scenarios
   • ✅ Environment variables remain safely protected
   • ✅ OSTest passed without regressions
   
   ### Related Issues
   
   Fixes potential race conditions in environment variable access during interrupt handling.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] sched/environ: add interrupt context check to getenv [nuttx]

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 merged PR #18034:
URL: https://github.com/apache/nuttx/pull/18034


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org