mirror of
https://github.com/johndoe6345789/SparkOS.git
synced 2026-04-24 13:34:56 +00:00
Address code review feedback: fix buffer overflows and remove remaining user configs
Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com>
This commit is contained in:
@@ -90,7 +90,6 @@ chmod 755 /staging/root/sbin/init
|
|||||||
echo "sparkos" > /staging/root/etc/hostname
|
echo "sparkos" > /staging/root/etc/hostname
|
||||||
echo "127.0.0.1 localhost" > /staging/root/etc/hosts
|
echo "127.0.0.1 localhost" > /staging/root/etc/hosts
|
||||||
echo "127.0.1.1 sparkos" >> /staging/root/etc/hosts
|
echo "127.0.1.1 sparkos" >> /staging/root/etc/hosts
|
||||||
echo "spark:x:1000:" >> /staging/root/etc/group
|
|
||||||
|
|
||||||
# Copy README to root partition
|
# Copy README to root partition
|
||||||
cp /build/config/image-readme.txt /staging/root/README.txt
|
cp /build/config/image-readme.txt /staging/root/README.txt
|
||||||
|
|||||||
@@ -65,7 +65,6 @@ chmod 755 /staging/root/sbin/init
|
|||||||
echo "sparkos" > /staging/root/etc/hostname
|
echo "sparkos" > /staging/root/etc/hostname
|
||||||
echo "127.0.0.1 localhost" > /staging/root/etc/hosts
|
echo "127.0.0.1 localhost" > /staging/root/etc/hosts
|
||||||
echo "127.0.1.1 sparkos" >> /staging/root/etc/hosts
|
echo "127.0.1.1 sparkos" >> /staging/root/etc/hosts
|
||||||
echo "spark:x:1000:" >> /staging/root/etc/group
|
|
||||||
|
|
||||||
# Copy README to root partition
|
# Copy README to root partition
|
||||||
cp /build/config/image-readme.txt /staging/root/README.txt
|
cp /build/config/image-readme.txt /staging/root/README.txt
|
||||||
|
|||||||
11
src/init.c
11
src/init.c
@@ -23,6 +23,7 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
static void signal_handler(int sig) {
|
static void signal_handler(int sig) {
|
||||||
if (sig == SIGCHLD) {
|
if (sig == SIGCHLD) {
|
||||||
@@ -81,6 +82,7 @@ static int init_network_interface(const char *ifname) {
|
|||||||
// Prepare interface request structure
|
// Prepare interface request structure
|
||||||
memset(&ifr, 0, sizeof(ifr));
|
memset(&ifr, 0, sizeof(ifr));
|
||||||
strncpy(ifr.ifr_name, ifname, IFNAMSIZ - 1);
|
strncpy(ifr.ifr_name, ifname, IFNAMSIZ - 1);
|
||||||
|
ifr.ifr_name[IFNAMSIZ - 1] = '\0'; // Ensure null termination
|
||||||
|
|
||||||
// Get current flags
|
// Get current flags
|
||||||
if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0) {
|
if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0) {
|
||||||
@@ -148,12 +150,17 @@ static int mount_fs(const char *source, const char *target, const char *fstype,
|
|||||||
* No dependency on mkdir binary
|
* No dependency on mkdir binary
|
||||||
*/
|
*/
|
||||||
static int mkdir_p(const char *path) {
|
static int mkdir_p(const char *path) {
|
||||||
char tmp[256];
|
char tmp[PATH_MAX];
|
||||||
char *p = NULL;
|
char *p = NULL;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
|
len = strlen(path);
|
||||||
|
if (len >= PATH_MAX) {
|
||||||
|
errno = ENAMETOOLONG;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
snprintf(tmp, sizeof(tmp), "%s", path);
|
snprintf(tmp, sizeof(tmp), "%s", path);
|
||||||
len = strlen(tmp);
|
|
||||||
if (tmp[len - 1] == '/')
|
if (tmp[len - 1] == '/')
|
||||||
tmp[len - 1] = 0;
|
tmp[len - 1] = 0;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user