Skip to content
This repository was archived by the owner on Jun 18, 2021. It is now read-only.

Commit 7cd3f76

Browse files
committed
Add local secure_getenv() and fix sizeof call
1 parent a46a004 commit 7cd3f76

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

src/node_report.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include <VersionHelpers.h>
2222
#else
2323
#include <sys/time.h>
24-
#include <unistd.h>
2524
#include <sys/resource.h>
2625
#include <inttypes.h>
2726
#include <cxxabi.h>
@@ -561,7 +560,7 @@ void PrintNativeStack(FILE* fp) {
561560
if (SymFromAddr(hProcess, dwAddress, &dwOffset64, pSymbol)) {
562561
DWORD dwOffset = 0;
563562
IMAGEHLP_LINE64 line;
564-
line.SizeOfStruct = sizeof(IMAGEHLP_LINE64);
563+
line.SizeOfStruct = sizeof(line);
565564
if (SymGetLineFromAddr64(hProcess, dwAddress, &dwOffset, &line)) {
566565
fprintf(fp, "%2d: [pc=0x%p] %s [+%d] in %s: line: %lu\n", i, pSymbol->Address, pSymbol->Name, dwOffset, line.FileName, line.LineNumber);
567566
} else {

src/node_report.h

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22
#define SRC_NODE_REPORT_H_
33

44
#include "nan.h"
5-
#if !defined(_WIN32) && !defined(__APPLE__)
5+
#ifndef _WIN32
6+
#include <unistd.h>
7+
#include <sys/types.h>
8+
#ifndef __APPLE__
69
#include <features.h>
710
#endif
11+
#endif
812

913
namespace nodereport {
1014

@@ -40,14 +44,14 @@ unsigned int ProcessNodeReportVerboseSwitch(const char* args);
4044

4145
void SetLoadTime();
4246

43-
// secure_getenv() only available in glibc, revert to getenv() otherwise
44-
#if defined(__GLIBC__)
45-
#if !__GLIBC_PREREQ(2, 17)
46-
#define secure_getenv getenv
47-
#endif // !__GLIBC_PREREQ(2, 17)
48-
#else
49-
#define secure_getenv getenv
50-
#endif // defined(__GLIBC__)
47+
// Local implementation of secure_getenv()
48+
inline const char* secure_getenv(const char* key) {
49+
#ifndef _WIN32
50+
if (getuid() != geteuid() || getgid() != getegid())
51+
return nullptr;
52+
#endif
53+
return getenv(key);
54+
}
5155

5256
// Emulate arraysize() on Windows pre Visual Studio 2015
5357
#if defined(_MSC_VER) && _MSC_VER < 1900

0 commit comments

Comments
 (0)