Security Update #6

Merged
raul merged 25 commits from testing into main 2024-05-17 08:00:14 +02:00
1 changed files with 16 additions and 9 deletions
Showing only changes of commit a21199a6e0 - Show all commits

View File

@ -72,12 +72,12 @@ func Client() {
defer conn.Close()
data.Server = conn
nameRequest, err := receiveMessage(conn)
nameRequest, b, err := receiveMessage(conn)
if err != nil {
log.Fatalf("Error occurred reading from server while requesting name: %v\n", err)
}
fmt.Print(nameRequest)
test := make([]byte, 2048)
test := make([]byte, b)
copy(test, "Password: ")
if nameRequest == string(test) {
@ -87,7 +87,7 @@ func Client() {
}
conn.Write([]byte(pass))
nameRequest, err := receiveMessage(conn)
nameRequest, _, err := receiveMessage(conn)
if err != nil {
if err != io.EOF {
log.Fatalf("Error occurred reading from server while requesting name: %v\n", err)
@ -113,7 +113,7 @@ func listenMessages(g *gocui.Gui) {
log.Panicln(err)
}
for {
messageFromServer, err := receiveMessage(data.Server)
messageFromServer, _, err := receiveMessage(data.Server)
if err != nil {
// What the hell is this
if err == gocui.ErrQuit {
@ -130,13 +130,20 @@ func listenMessages(g *gocui.Gui) {
}
}
func receiveMessage(conn net.Conn) (s string, err error) {
func receiveMessage(conn net.Conn) (s string, b int, err error) {
serverMessage := make([]byte, 2048)
if _, err := conn.Read(serverMessage); err != nil {
return "", err
n, err := conn.Read(serverMessage)
if err != nil {
return "", 0, err
}
finalMessage := string(serverMessage)
return finalMessage, nil
serverMessageReduced := make([]byte, n)
copy(serverMessageReduced, serverMessage)
finalMessage := string(serverMessageReduced)
serverMessage = nil
return finalMessage, n, nil
}
func scanLine() (line string, err error) {