Skip to content

How to check CWE-404 when throw exception #17319

Closed as not planned
Closed as not planned
@ysuLihua

Description

@ysuLihua

Description of the issue

This is test code:
test_throw.h

#define _O_RDONLY      0x0000  // open for reading only
namespace OCKIO {
namespace MSG {
void Throw(const char* func, const char* file)
{
    throw("error");
}
}
};

test_throw.cpp

#include "test_throw.h"
#include <fcntl.h>
#include <unistd.h> 
#include <sys/types.h> 
#include <sys/stat.h> 

namespace OCKIO {
namespace SHORE {
namespace PROCESSOR {
class TransPosix {
private:
    void ReadJewel();
};
void TransPosix::ReadJewel(){
    auto fdData = open("a.txt", 0x0000);
    if (fdData < 0) {
        MSG::Throw("error", "file opening failed");
    }
    if (lseek(fdData, 5, SEEK_SET) > 20){
        // no close
        **MSG::Throw("error", "file opening failed");**
    }
    close(fdData);
}
}
}
};

How can I check fdData is closed, before throw?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Staleawaiting-responseThe CodeQL team is awaiting further input or clarification from the original reporter of this issue.questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions