nmblookup: Warn user if netbios name is too long.
authorAndreas Schneider <asn@samba.org>
Fri, 30 Jan 2015 13:37:06 +0000 (14:37 +0100)
committerJeremy Allison <jra@samba.org>
Tue, 24 Feb 2015 00:01:10 +0000 (01:01 +0100)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Tue Feb 24 01:01:10 CET 2015 on sn-devel-104

libcli/nbt/tools/nmblookup.c
source3/utils/nmblookup.c

index 9b875b08c49192170fa51d6fcd6671a1156e6ebe..afb81c745cd1cd51f9e036a0f35a558161c8412a 100644 (file)
 #include "../libcli/nbt/libnbt.h"
 #include "param/param.h"
 
+#include <string.h>
+
+#define MAX_NETBIOSNAME_LEN 16
+
 /* command line options */
 static struct {
        const char *broadcast_address;
@@ -190,6 +194,7 @@ static bool process_one(struct loadparm_context *lp_ctx, struct tevent_context *
        struct socket_address *all_zero_addr;
        struct nbt_name_socket *nbtsock;
        NTSTATUS status = NT_STATUS_OK;
+       size_t nbt_len;
        bool ret = true;
 
        if (!options.case_sensitive) {
@@ -212,6 +217,14 @@ static bool process_one(struct loadparm_context *lp_ctx, struct tevent_context *
                node_name = talloc_strdup(tmp_ctx, name);
        }
 
+       nbt_len = strlen(node_name);
+       if (nbt_len > MAX_NETBIOSNAME_LEN - 1) {
+               printf("The specified netbios name [%s] is too long.\n",
+                      node_name);
+               talloc_free(tmp_ctx);
+               return false;
+       }
+
        nbtsock = nbt_name_socket_init(tmp_ctx, ev);
        
        if (options.root_port) {
index 78548e9d68c0b2debed8dbcbfc30c700a7a5b6c4..a119b3eabe82eb55b17689e37cc5eecb09e0b4cb 100644 (file)
@@ -320,6 +320,7 @@ int main(int argc, const char *argv[])
        while(poptPeekArg(pc)) {
                char *p;
                struct in_addr ip;
+               size_t nbt_len;
 
                fstrcpy(lookup,poptGetArg(pc));
 
@@ -349,6 +350,14 @@ int main(int argc, const char *argv[])
                        sscanf(++p,"%x",&lookup_type);
                }
 
+               nbt_len = strlen(lookup);
+               if (nbt_len > MAX_NETBIOSNAME_LEN - 1) {
+                       d_printf("The specified netbios name [%s] is too long!\n",
+                                lookup);
+                       continue;
+               }
+
+
                if (!query_one(lookup, lookup_type)) {
                        rc = 1;
                        d_printf( "name_query failed to find name %s", lookup );