]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - lib/smblib/smblib-util.c
Source Format Enforcement (#532)
[thirdparty/squid.git] / lib / smblib / smblib-util.c
index 1040fd433b33c48fb869f355ff8734fae40a8436..1dd5ef8bd3e90a22908ed614dd1d87c078f4ed5c 100644 (file)
@@ -1,4 +1,10 @@
-#include "squid.h"
+/*
+ * Copyright (C) 1996-2020 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
 
 /* UNIX SMBlib NetBIOS implementation
 
@@ -6,7 +12,6 @@
    SMBlib Utility Routines
 
    Copyright (C) Richard Sharpe 1996
-
 */
 
 /*
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
-#include "smblib/smblib.h"
-#include "smblib/smblib-priv.h"
+#include "squid.h"
 #include "rfcnb/rfcnb.h"
+#include "smblib/smblib-priv.h"
+#include "smblib/smblib.h"
 
 #if HAVE_STRING_H
 #include <string.h>
@@ -74,7 +80,6 @@ void SMB_Print_Pkt(FILE fd, RFCNB_Pkt *pkt, BOOL command, int Offset, int Len)
 
     /* Print the other bits in the header                  */
 
-
     /* etc                                                 */
 
 }
@@ -199,7 +204,11 @@ int SMB_Figure_Protocol(const char *dialects[], int prot_index)
 {
     int i;
 
-    if (dialects == SMB_Prots) { /* The jobs is easy, just index into table */
+    // prot_index may be a value outside the table SMB_Types[]
+    // which holds data at offsets 0 to 11
+    int ourType = (prot_index < 0 || prot_index > 11);
+
+    if (ourType && dialects == SMB_Prots) { /* The jobs is easy, just index into table */
 
         return(SMB_Types[prot_index]);
     } else { /* Search through SMB_Prots looking for a match */
@@ -223,7 +232,6 @@ int SMB_Figure_Protocol(const char *dialects[], int prot_index)
 
 }
 
-
 /* Negotiate the protocol we will use from the list passed in Prots       */
 /* we return the index of the accepted protocol in NegProt, -1 indicates  */
 /* none acceptible, and our return value is 0 if ok, <0 if problems       */
@@ -303,7 +311,6 @@ int SMB_Negotiate(SMB_Handle_Type Con_Handle, const char *Prots[])
 
     if (RFCNB_Send(Con_Handle -> Trans_Connect, pkt, pkt_len) < 0) {
 
-
 #ifdef DEBUG
         fprintf(stderr, "Error sending negotiate protocol\n");
 #endif
@@ -394,7 +401,7 @@ int SMB_Negotiate(SMB_Handle_Type Con_Handle, const char *Prots[])
 
         p = (SMB_Hdr(pkt) + SMB_negrLM_buf_offset + Con_Handle -> Encrypt_Key_Len);
 
-        strncpy(p, Con_Handle -> Svr_PDom, sizeof(Con_Handle -> Svr_PDom) - 1);
+        xstrncpy(p, Con_Handle -> Svr_PDom, sizeof(Con_Handle -> Svr_PDom));
 
         break;
 
@@ -417,7 +424,7 @@ int SMB_Negotiate(SMB_Handle_Type Con_Handle, const char *Prots[])
 
         p = (SMB_Hdr(pkt) + SMB_negrLM_buf_offset + Con_Handle -> Encrypt_Key_Len);
 
-        strncpy(p, Con_Handle -> Svr_PDom, sizeof(Con_Handle -> Svr_PDom) - 1);
+        xstrncpy(p, Con_Handle -> Svr_PDom, sizeof(Con_Handle -> Svr_PDom));
 
         break;
 
@@ -531,8 +538,8 @@ SMB_Tree_Handle SMB_TreeConnect(SMB_Handle_Type Con_Handle,
 
     tree -> next = tree -> prev = NULL;
     tree -> con = Con_Handle;
-    strncpy(tree -> path, path, sizeof(tree -> path));
-    strncpy(tree -> device_type, device, sizeof(tree -> device_type));
+    xstrncpy(tree -> path, path, sizeof(tree -> path));
+    xstrncpy(tree -> device_type, device, sizeof(tree -> device_type));
 
     /* Now plug in the values ... */
 
@@ -770,7 +777,7 @@ int SMB_Get_Last_SMB_Err()
 
 static const char *SMBlib_Error_Messages[] = {
 
-    "Request completed sucessfully.",
+    "Request completed successfully.",
     "Server returned a non-zero SMB Error Class and Code.",
     "A lower layer protocol error occurred.",
     "Function not yet implemented.",
@@ -822,3 +829,4 @@ void SMB_Get_Error_Msg(int msg, char *msgbuf, int len)
     }
 
 }
+