Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6183499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:22:34+00:00 2026-05-24T01:22:34+00:00

Is there a way to programmatically check if a single C source file is

  • 0

Is there a way to programmatically check if a single C source file is potentially harmful?

I know that no check will yield 100% accuracy — but am interested at least to do some basic checks that will raise a red flag if some expressions / keywords are found. Any ideas of what to look for?

Note: the files I will be inspecting are relatively small in size (few 100s of lines at most), implementing numerical analysis functions that all operate in memory. No external libraries (except math.h) shall be used in the code. Also, no I/O should be used (functions will be run with in-memory arrays).

Given the above, are there some programmatic checks I could do to at least try to detect harmful code?

Note: since I don’t expect any I/O, if the code does I/O — it is considered harmful.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T01:22:35+00:00Added an answer on May 24, 2026 at 1:22 am

    If you want to make sure it’s not calling anything not allowed, then compile the piece of code and examine what it’s linking to (say via nm). Since you’re hung up on doing this by a “programmatic” method, just use python/perl/bash to compile then scan the name list of the object file.

    There’s not a lot you can do about buffer overwrites for statically defined buffers, but you could link against an electric-fence type memory allocator to prevent dynamically allocated buffer overruns.

    You could also compile and link the C-file in question against a driver which would feed it typical data while running under valgrind which could help detect poorly or maliciously written code.

    In the end, however, you’re always going to run up against the “does this routine terminate” question, which is famous for being undecidable. A practical way around this would be to compile your program and run it from a driver which would alarm-out after a set period of reasonable time.

    EDIT: Example showing use of nm:

    Create a C snippet defining function foo which calls fopen:

    #include <stdio.h>
    foo() {
       FILE *fp = fopen("/etc/passwd", "r");
    }
    

    Compile with -c, and then look at the resulting object file:

    $ gcc -c foo.c
    $ nm foo.o
    0000000000000000 T foo
                     U fopen
    

    Here you’ll see that there are two symbols in the foo.o object file. One is defined, foo, the name of the subroutine we wrote. And one is undefined, fopen, which will be linked to its definition when the object file is linked together with the other C-files and necessary libraries. Using this method, you can see immediately if the compiled object is referencing anything outside of its own definition, and by your rules, can considered to be “bad”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to programmatically download a single file from a remote git
Is there any way that I can programmatically create (and I guess access) hidden
Is there a way to programmatically check if IPv6 is installed/enabled on windows using
What is the best way to programmatically check if a PDF file is a
is there a way to check programmatically (via ioctl(), etc.) or by reading a
Is there any way (programmatically) that i can find the location of Resource folder.
Is there any way to query ACLs on Linux programmatically? Given a file or
Is there a way to check whether your code base is obfuscated programmatically? In
Is there any way to programmatically check the priority of a window messages in
In mercurial, is there an easy way to programmatically check out the 'latest' tag?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.