You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by "github-code-scanning[bot] (via GitHub)" <gi...@apache.org> on 2023/09/06 21:13:02 UTC

[GitHub] [trafficcontrol] github-code-scanning[bot] commented on a diff in pull request #7746: Add TM integration and separate docker-compose services for Varnish

github-code-scanning[bot] commented on code in PR #7746:
URL: https://github.com/apache/trafficcontrol/pull/7746#discussion_r1317838053


##########
infrastructure/cdn-in-a-box/varnish/vstats.go:
##########
@@ -0,0 +1,110 @@
+package main
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import (
+	"encoding/json"
+	"flag"
+	"fmt"
+	"log"
+	"net/http"
+	"os"
+	"os/exec"
+	"strconv"
+	"strings"
+)
+
+type vstats struct {
+	ProcLoadavg  string `json:"proc.loadavg"`
+	ProcNetDev   string `json:"proc.net.dev"`
+	InfSpeed     int64  `json:"inf_speed"`
+	NotAvailable bool   `json:"not_available"`
+	// TODO: stats
+}
+
+func getSystemData(inf string) vstats {
+	var vstats vstats
+	loadavg, err := os.ReadFile("/proc/loadavg")
+	if err != nil {
+		log.Printf("failed to read /proc/loadavg: %s\n", err)
+	}
+	vstats.ProcLoadavg = strings.TrimSpace(string(loadavg))
+
+	procNetDev, err := os.ReadFile("/proc/net/dev")
+	if err != nil {
+		log.Printf("failed to read /proc/net/dev: %s\n", err)
+	}
+
+	parts := strings.Split(string(procNetDev), "\n")
+	for _, line := range parts {
+		if strings.HasPrefix(strings.TrimSpace(line), inf) {
+			vstats.ProcNetDev = strings.TrimSpace(line)
+			break
+		}
+	}
+
+	infSpeedFile := fmt.Sprintf("/sys/class/net/%s/speed", inf)
+	speedStr, err := os.ReadFile(infSpeedFile)

Review Comment:
   ## Uncontrolled data used in path expression
   
   This path depends on a [user-provided value](1).
   
   [Show more details](https://github.com/apache/trafficcontrol/security/code-scanning/307)



-- 
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: issues-unsubscribe@trafficcontrol.apache.org

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